This commit is contained in:
parent
412a95613c
commit
2d45e56f7a
5 changed files with 61 additions and 65 deletions
|
|
@ -1,6 +1,11 @@
|
|||
(* TODO response
|
||||
use ErrorDetail *)
|
||||
|
||||
let encode_error_detail err =
|
||||
match Api.(encode ErrorDetail.jsont err) with
|
||||
| Error e -> Fmt.failwith "json encoding error on `ErrorDetail`: %s." e
|
||||
| Ok s -> s
|
||||
|
||||
let respond_json req content status =
|
||||
let open Vif.Response in
|
||||
let open Syntax in
|
||||
|
|
@ -12,10 +17,10 @@ let mk_error_content ?hint _status =
|
|||
let open Api in
|
||||
let code = -1 in
|
||||
let err = ErrorDetail.make ?hint code in
|
||||
encode_exn ErrorDetail.jsont err
|
||||
encode_error_detail err
|
||||
|
||||
let error ~hint req =
|
||||
Logs.err (fun m -> m "internal server error: %s" hint);
|
||||
Logs.err (fun m -> m "error: %s" hint);
|
||||
let body = mk_error_content ~hint `Internal_server_error in
|
||||
respond_json req body `Internal_server_error
|
||||
|
||||
|
|
@ -28,6 +33,13 @@ let ok content req =
|
|||
Logs.debug (fun m -> m "ok");
|
||||
respond_json req content `OK
|
||||
|
||||
let no_content () =
|
||||
Logs.debug (fun m -> m "no content");
|
||||
let open Vif.Response in
|
||||
let open Syntax in
|
||||
let* () = empty in
|
||||
respond `No_content
|
||||
|
||||
let not_modified () =
|
||||
Logs.debug (fun m -> m "not modified");
|
||||
let open Vif.Response in
|
||||
|
|
@ -37,3 +49,6 @@ let not_modified () =
|
|||
|
||||
let result res req =
|
||||
match res with Error hint -> error ~hint req | Ok content -> ok content req
|
||||
|
||||
let result_no_content res req =
|
||||
match res with Error hint -> error ~hint req | Ok () -> no_content ()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue