Skip to content

Commit c68c19b

Browse files
author
Jan Rochel
authored
Merge pull request #167 from ocsigen/fixspinn
Ot_spinner: Error message improvements
2 parents c18369d + 381de98 commit c68c19b

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

css/ot_icons.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
background-color: black ;
5959
}
6060

61+
.ot-icon-error::before,
6162
.ot-icon-question::before {
6263
content: '?' ;
6364
display: block ;

src/widgets/ot_spinner.eliom

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,31 @@
2323
[%%shared open Eliom_content.Html.F ]
2424
[%%client open Eliom_shared ]
2525

26-
let%shared default_fail e =
26+
let%shared default_fail_fun e =
2727
[
2828
if Eliom_config.get_debugmode ()
2929
then em [ pcdata (Printexc.to_string e) ]
30-
else em ~a:[ a_class ["ot-icon-question"] ]
31-
[ pcdata (Printexc.to_string e) ] ]
30+
else begin
31+
let e = Printexc.to_string e in
32+
ignore [%client (Firebug.console##error
33+
(Js.string ("Ot_spinner content failed with "^ ~%e))
34+
: unit)];
35+
em ~a:[ a_class ["ot-icon-error"] ] []
36+
end
37+
]
38+
39+
let%shared default_fail_ref
40+
: (exn -> Html_types.div_content Eliom_content.Html.elt list) ref
41+
= ref default_fail_fun
42+
43+
let%shared default_fail e =
44+
(!default_fail_ref e
45+
: Html_types.div_content Eliom_content.Html.elt list
46+
:> [< Html_types.div_content ] Eliom_content.Html.elt list)
47+
48+
let%shared set_default_fail f = default_fail_ref :=
49+
(f : exn -> [< Html_types.div_content ] Eliom_content.Html.elt list
50+
:> exn -> Html_types.div_content Eliom_content.Html.elt list)
3251

3352
let%server with_spinner ?(a = []) ?fail thread =
3453
let a = (a :> Html_types.div_attrib attrib list) in
@@ -72,7 +91,10 @@ let cl_spinner = "ot-icon-spinner"
7291

7392
let replace_content ?fail elt thread =
7493
let fail = match fail with
75-
| Some fail -> fail
94+
| Some fail ->
95+
(fail
96+
: exn -> [< Html_types.div_content ] Eliom_content.Html.elt list Lwt.t
97+
:> exn -> Html_types.div_content Eliom_content.Html.elt list Lwt.t)
7698
| None -> fun e -> Lwt.return (default_fail e)
7799
in
78100
inc_active_spinners ();

src/widgets/ot_spinner.eliomi

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
3434
If you want the spinner on both sides, you can use [with_spinner_no_lwt]
3535
and [Eliom_content.Html.C.node].
36+
37+
Function [fail] will be used to display block in case an exception is
38+
raised.
3639
*)
3740
val with_spinner :
3841
?a:[< Html_types.div_attrib ] Eliom_content.Html.attrib list ->
@@ -57,9 +60,9 @@ val with_spinner_no_lwt :
5760
generated by [thread]. The [elt] has be a D-node. Until [thread] is
5861
finished [elt] is transformed into a spinner. *)
5962
val replace_content :
60-
?fail:(exn -> ([> Html_types.em] as 'b) Eliom_content.Html.elt list Lwt.t) ->
63+
?fail:(exn -> [< Html_types.div_content] Eliom_content.Html.elt list Lwt.t) ->
6164
'a Eliom_content.Html.elt ->
62-
'b Eliom_content.Html.elt list Lwt.t -> unit Lwt.t
65+
Html_types.div_content Eliom_content.Html.elt list Lwt.t -> unit Lwt.t
6366

6467
(** the number of spinners currently spinning *)
6568
val num_active_spinners : int Eliom_shared.React.S.t
@@ -68,3 +71,7 @@ val num_active_spinners : int Eliom_shared.React.S.t
6871
val onloaded : unit Eliom_shared.React.E.t
6972
(** do an action once no spinners are spinning (could be right away) *)
7073
val when_loaded : (unit -> unit) -> unit
74+
75+
(** Change the default function used to display error messages *)
76+
val set_default_fail :
77+
(exn -> [< Html_types.div_content ] Eliom_content.Html.elt list) -> unit

0 commit comments

Comments
 (0)