12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849(**************************************************************************)(* *)(* Copyright 2018-2023 OCamlPro *)(* *)(* All rights reserved. This file is distributed under the terms of the *)(* GNU Lesser General Public License version 2.1, with the special *)(* exception on linking described in the file LICENSE. *)(* *)(**************************************************************************)type'at={code:int;body:'a;headers:(string*string)list;}letreturn?(code=-1)?(headers=[])body=Lwt.return{code;body;headers}letnot_found()=return~code:404""letheaders=["content-type","application/json"]letcannot_parse(descr,msg,path)=letbody=EzEncoding.constructJson_encoding.any_ezjson_value@@`O["error",`String("Cannot parse path argument "^descr.EzAPI.Arg.name);"path",`String(String.concat"/"path);"msg",`Stringmsg]inreturn~code:400~headersbodyletmethod_not_allowed()=return~code:405""letdestruct_exceptionexn=letbody=EzEncoding.constructJson_encoding.any_ezjson_value@@`O["error",`String"Destruct exception";"exception",`String(Printexc.to_stringexn)]inreturn~code:400~headersbodyletunsupported_media_typec=letc=matchcwithNone->"none"|Somec->cinletbody=EzEncoding.constructJson_encoding.any_ezjson_value@@`O["error",`String"Unsupported Media Type";"content_type",`Stringc]inreturn~code:415~headersbodyletserver_errorexn=letbody=EzEncoding.constructJson_encoding.any_ezjson_value@@`O["error",`String"Server Error";"msg",`String(Printexc.to_stringexn)]inreturn~code:500~headersbody