import{logger as e}from"../../logger/index.mjs";import{HttpStatusCodes as t}from"../httpStatusCodes.mjs";import{formatPaginatedResponse as n,formatResponse as r}from"../responseData.mjs";import{errorData as i}from"./errorCodes.mjs";import*as a from"@intlayer/types/locales";import{t as o}from"fastify-intlayer";const s=(e,t,n,r,a=!1)=>{let o=i[t],s=r??o.statusCode;l(e,t,o.title,o.message,n,s,a)},c=(e,n,r,i=!1)=>{if(!n.isAppError){l(e,n.errorKey??`UNKNOWN_ERROR`,`Error`,n.message??JSON.stringify(n),void 0,n.httpStatusCode??t.INTERNAL_SERVER_ERROR_500,i);return}let a=n.isMultilingual??!1;l(e,n.errorKey,a?n.multilingualTitle:n.title,a?n.multilingualMessage:n.message,n.messageDetails??r,n.httpStatusCode,i)},l=(i,s,c,l,u,d,f=!1)=>{let p=o(c,a.ENGLISH),m=o(l,a.ENGLISH);e.error(m,u);let h=d??t.INTERNAL_SERVER_ERROR_500;if(f){let e=n({error:{code:s,title:p,message:m},status:h});`status`in i&&`json`in i?i.status(h).json(e):i.code(h).send(e);return}let g=r({error:{code:s,title:p,message:m,...u},status:h});`status`in i&&`json`in i?i.status(h).json(g):i.code(h).send(g)},u=(t,n,s)=>{let c=i[t],l=s??c.statusCode,u=o(c.title,a.ENGLISH),d=o(c.message,a.ENGLISH);return e.error(d,n),r({error:{code:t,title:u,message:d,...n},status:l})},d={handleGenericErrorResponse:s,handleAppErrorResponse:c,handleCustomErrorResponse:l,formatGenericErrorResponse:u};export{d as ErrorHandler,u as formatGenericErrorResponse,c as handleAppErrorResponse,l as handleCustomErrorResponse,s as handleGenericErrorResponse};
//# sourceMappingURL=ErrorHandler.mjs.map