rename
This commit is contained in:
parent
7baba82a10
commit
dad5bd9d35
6 changed files with 66 additions and 82 deletions
39
src/respond.ml
Normal file
39
src/respond.ml
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
(* TODO response
|
||||
use ErrorDetail *)
|
||||
|
||||
let respond_json req content status =
|
||||
let open Vif.Response in
|
||||
let open Syntax in
|
||||
let* () = add ~field:"content-type" "application/json" in
|
||||
let* () = with_string req content in
|
||||
respond status
|
||||
|
||||
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
|
||||
|
||||
let error ~hint req =
|
||||
Logs.err (fun m -> m "internal server error: %s" hint);
|
||||
let body = mk_error_content ~hint `Internal_server_error in
|
||||
respond_json req body `Internal_server_error
|
||||
|
||||
let bad_request ?hint req =
|
||||
Logs.err (fun m -> m "bad request");
|
||||
let body = mk_error_content ?hint `Bad_request in
|
||||
respond_json req body `Bad_request
|
||||
|
||||
let ok content req =
|
||||
Logs.debug (fun m -> m "ok");
|
||||
respond_json req content `OK
|
||||
|
||||
let not_modified () =
|
||||
Logs.debug (fun m -> m "not modified");
|
||||
let open Vif.Response in
|
||||
let open Syntax in
|
||||
let* () = empty in
|
||||
respond `Not_modified
|
||||
|
||||
let result res req =
|
||||
match res with Error hint -> error ~hint req | Ok content -> ok content req
|
||||
Loading…
Add table
Add a link
Reference in a new issue