Skip to content

Commit

Permalink
Pass Dream.error object to error templates
Browse files Browse the repository at this point in the history
Resolves aantron#162.
  • Loading branch information
aantron committed Sep 28, 2021
1 parent 469db38 commit 431cf8c
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions docs/web/postprocess/index.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1229,13 +1229,13 @@ let initialize_log_replacement = {|
</pre>|}

let error_template_expected = {|<div class="spec value" id="val-error_template">
<a href="#val-error_template" class="anchor"></a><code><span><span class="keyword">val</span> error_template : <span><span>(<span><span>string option</span> <span class="arrow">-&gt;</span></span> <span><a href="#type-response">response</a> <span class="arrow">-&gt;</span></span> <span><a href="#type-response">response</a> <a href="#type-promise">promise</a></span>)</span> <span class="arrow">-&gt;</span></span> <a href="#type-error_handler">error_handler</a></span></code>
<a href="#val-error_template" class="anchor"></a><code><span><span class="keyword">val</span> error_template : <span><span>(<span><a href="#type-error">error</a> <span class="arrow">-&gt;</span></span> <span><span>string option</span> <span class="arrow">-&gt;</span></span> <span><a href="#type-response">response</a> <span class="arrow">-&gt;</span></span> <span><a href="#type-response">response</a> <a href="#type-promise">promise</a></span>)</span> <span class="arrow">-&gt;</span></span> <a href="#type-error_handler">error_handler</a></span></code>
</div>
|}

let error_template_replacement = {|
<pre><span class="keyword">val</span> error_template :
(string option -> <a href="#val-response">response</a> -> <a href="#val-response">response</a> <a href="#type-promise">promise</a>) ->
(<a href="#type-error">error</a> -> string option -> <a href="#val-response">response</a> -> <a href="#val-response">response</a> <a href="#type-promise">promise</a>) ->
<a href="#type-error_handler">error_handler</a>
</pre>
|}
Expand Down
2 changes: 1 addition & 1 deletion example/9-error/error.eml.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let my_error_template debug_info suggested_response =
let my_error_template _error debug_info suggested_response =
let status = Dream.status suggested_response in
let code = Dream.status_to_int status
and reason = Dream.status_to_string status in
Expand Down
4 changes: 2 additions & 2 deletions src/dream.mli
Original file line number Diff line number Diff line change
Expand Up @@ -1887,14 +1887,14 @@ type error_handler = error -> response option promise
{!Dream.type-error}. *)

val error_template :
(string option -> response -> response promise) -> error_handler
(error -> string option -> response -> response promise) -> error_handler
(** Builds an {!error_handler} from a template. See example
{{:https://github.com/aantron/dream/tree/master/example/9-error#files}
[9-error]} \[{{:http://dream.as/9-error} playground}\].
{[
let my_error_handler =
Dream.error_template (fun ~debug_dump suggested_response ->
Dream.error_template (fun _error debug_dump suggested_response ->
let body =
match debug_dump with
| Some string -> Dream.html_escape string
Expand Down
4 changes: 2 additions & 2 deletions src/http/error_handler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,12 @@ let customize template (error : Dream.error) =
site of the error handler already has error handlers for catching double
faults. *)
response
|> template debug_dump
|> template error debug_dump
|> Lwt.map (fun response -> Some response)



let default_template debug_dump response =
let default_template _error debug_dump response =
match debug_dump with
| None -> Lwt.return response
| Some debug_dump ->
Expand Down
2 changes: 1 addition & 1 deletion src/http/error_handler.mli
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module Dream = Dream__pure.Inmost

val default : Dream.error_handler
val customize :
(string option -> Dream.response -> Dream.response Lwt.t) ->
(Dream.error -> string option -> Dream.response -> Dream.response Lwt.t) ->
Dream.error_handler


Expand Down

0 comments on commit 431cf8c

Please sign in to comment.