@sigiljs/sigil
Version:
TypeScript-first Node.js HTTP framework offering schema-driven routing, modifier-based middleware, plugin extensibility, and flexible response templating
2 lines (1 loc) • 718 B
JavaScript
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("../../utils/safe-json.js"),r=require("../../responses/sigil-response.js"),o=e=>{if(e instanceof Error)return{content:t.jsonStringify({error:e.name??"Unknown error",content:e.message??"Unknown error occurred"},{throw:!0}),code:e.code??500,headers:{"content-type":"application/json",...e.headers.link}};let n=e instanceof r.default?e.headers.link:{};return(!Buffer.isBuffer(e)&&Object.keys(n).length===0||!("content-type"in n))&&(n={...n,"content-type":"application/json"}),{content:Buffer.isBuffer(e)?e:t.jsonStringify({error:null,content:e.content??e},{throw:!0}),headers:n,code:e?.code??200}};exports.defaultTemplate=o;