expose Response.Bad_req

This commit is contained in:
Simon Cruanes 2024-02-28 16:11:16 -05:00
parent 5a38ffdce7
commit 7de89bd555
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 8 additions and 2 deletions

View file

@ -63,6 +63,8 @@ let make ?headers ?(code = 200) r : t =
let fail ?headers ~code fmt = let fail ?headers ~code fmt =
Printf.ksprintf (fun msg -> make_raw ?headers ~code msg) fmt Printf.ksprintf (fun msg -> make_raw ?headers ~code msg) fmt
exception Bad_req = Bad_req
let fail_raise ~code fmt = let fail_raise ~code fmt =
Printf.ksprintf (fun msg -> raise (Bad_req (code, msg))) fmt Printf.ksprintf (fun msg -> raise (Bad_req (code, msg))) fmt

View file

@ -99,10 +99,14 @@ val fail : ?headers:Headers.t -> code:int -> ('a, unit, string, t) format4 -> 'a
Example: [fail ~code:404 "oh noes, %s not found" "waldo"]. Example: [fail ~code:404 "oh noes, %s not found" "waldo"].
*) *)
exception Bad_req of int * string
(** Exception raised by {!fail_raise} with the HTTP code and body *)
val fail_raise : code:int -> ('a, unit, string, 'b) format4 -> 'a val fail_raise : code:int -> ('a, unit, string, 'b) format4 -> 'a
(** Similar to {!fail} but raises an exception that exits the current handler. (** Similar to {!fail} but raises an exception that exits the current handler.
This should not be used outside of a (path) handler. This should not be used outside of a (path) handler.
Example: [fail_raise ~code:404 "oh noes, %s not found" "waldo"; never_executed()] Example: [fail_raise ~code:404 "oh noes, %s not found" "waldo"; never_executed()]
@raise Bad_req always
*) *)
val pp : Format.formatter -> t -> unit val pp : Format.formatter -> t -> unit