add result.ml; polymorphic variant errors + refacto
This commit is contained in:
parent
9fd3b5a3cc
commit
42b0ec1445
36 changed files with 949 additions and 954 deletions
|
|
@ -1,6 +1,7 @@
|
|||
let encode_error_detail err =
|
||||
match Api.(encode ErrorDetail.jsont err) with
|
||||
| Error e -> Fmt.failwith "json encoding error on `ErrorDetail`: %s." e
|
||||
match Api.encode Api.ErrorDetail.jsont err with
|
||||
| Error e ->
|
||||
Fmt.failwith "json encoding error on `ErrorDetail`: %a." Result.pp_err e
|
||||
| Ok s -> s
|
||||
|
||||
let respond_json req content status =
|
||||
|
|
@ -16,7 +17,8 @@ let mk_error_content ?hint _status =
|
|||
let err = ErrorDetail.make ?hint code in
|
||||
encode_error_detail err
|
||||
|
||||
let error ~hint req =
|
||||
let error err req =
|
||||
let hint = Fmt.str "%a" Result.pp_err err in
|
||||
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
|
||||
|
|
@ -45,7 +47,7 @@ let not_modified () =
|
|||
respond `Not_modified
|
||||
|
||||
let result res req =
|
||||
match res with Error hint -> error ~hint req | Ok content -> ok content req
|
||||
match res with Error e -> error e req | Ok content -> ok content req
|
||||
|
||||
let result_no_content res req =
|
||||
match res with Error hint -> error ~hint req | Ok () -> no_content ()
|
||||
match res with Error e -> error e req | Ok () -> no_content ()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue