@visulima/error-handler 2.0.0-alpha.10 → 2.0.0-alpha.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,25 @@
1
+ ## @visulima/error-handler [2.0.0-alpha.11](https://github.com/visulima/visulima/compare/@visulima/error-handler@2.0.0-alpha.10...@visulima/error-handler@2.0.0-alpha.11) (2026-04-08)
2
+
3
+ ### Bug Fixes
4
+
5
+ * **error-handler:** properly fix eslint errors in code ([591179f](https://github.com/visulima/visulima/commit/591179fb1b56587986449878a95abfc18f6d735b))
6
+ * **error-handler:** remove remaining eslint suppressions with proper code fixes ([58b05d6](https://github.com/visulima/visulima/commit/58b05d6cb5d98c29e0abe57af35120696504b22b))
7
+ * **error-handler:** resolve eslint errors ([ab613b8](https://github.com/visulima/visulima/commit/ab613b8683677fd0ca7e09b06b3fe94e59df9bd0))
8
+
9
+ ### Miscellaneous Chores
10
+
11
+ * apply linting and formatting fixes across packages ([5d150a5](https://github.com/visulima/visulima/commit/5d150a578f9ce861c791843c683deeb849b774a9))
12
+ * **error-debugging:** remove empty dependency objects from package.json ([7eb7c8e](https://github.com/visulima/visulima/commit/7eb7c8eba1394e515fa77c0f56baf41c0810de2e))
13
+ * **error-handler:** add tsconfig.eslint.json for type-aware linting ([8e52a91](https://github.com/visulima/visulima/commit/8e52a916c1b7a0262b5ef097985be5ccaa735401))
14
+ * **error-handler:** apply prettier formatting ([eeb50dd](https://github.com/visulima/visulima/commit/eeb50ddf301722cb7f1439001d2b1c06e88797ae))
15
+ * **error-handler:** migrate .prettierrc.cjs to prettier.config.js ([6fb8eb8](https://github.com/visulima/visulima/commit/6fb8eb8832335f8b249cded58fe78c3ee5edc000))
16
+
17
+
18
+ ### Dependencies
19
+
20
+ * **@visulima/boxen:** upgraded to 3.0.0-alpha.9
21
+ * **@visulima/error:** upgraded to 6.0.0-alpha.8
22
+
1
23
  ## @visulima/error-handler [2.0.0-alpha.10](https://github.com/visulima/visulima/compare/@visulima/error-handler@2.0.0-alpha.9...@visulima/error-handler@2.0.0-alpha.10) (2026-03-26)
2
24
 
3
25
  ### Features
@@ -1,4 +1,4 @@
1
1
  import type { IncomingMessage, ServerResponse } from "node:http";
2
2
  import type { ErrorHandler, ErrorHandlers } from "./types.d.d.ts";
3
- declare const createNegotiatedErrorHandler: <Request extends IncomingMessage, Response extends ServerResponse>(errorHandlers: ErrorHandlers, showTrace: boolean, defaultHtmlHandler?: ErrorHandler) => (error: Error, request: Request, response: Response) => Promise<void>;
3
+ declare const createNegotiatedErrorHandler: (errorHandlers: ErrorHandlers, showTrace: boolean, defaultHtmlHandler?: ErrorHandler) => (error: Error, request: IncomingMessage, response: ServerResponse) => Promise<void>;
4
4
  export default createNegotiatedErrorHandler;
@@ -1,4 +1,4 @@
1
- var l=Object.defineProperty;var n=(e,r)=>l(e,"name",{value:r,configurable:!0});import{getReasonPhrase as c}from"http-status-codes";import{a as m}from"../packem_shared/add-status-code-to-response-BE6paXjR.js";var g=Object.defineProperty,s=n((e,r)=>g(e,"name",{value:r,configurable:!0}),"n");const x=s((e={})=>async(r,d,t)=>{m(t,r),t.setHeader("content-type","text/html; charset=utf-8");const o=c(t.statusCode)||"Error",a=e.cspNonce?` nonce="${e.cspNonce}"`:"";if(e.errorPage){const i=typeof e.errorPage=="function"?await e.errorPage({error:r,reasonPhrase:o,request:d,response:t,statusCode:t.statusCode}):e.errorPage;if(i){t.end(i);return}}t.end(String.raw`<!DOCTYPE html>
1
+ var l=Object.defineProperty;var n=(e,r)=>l(e,"name",{value:r,configurable:!0});import{getReasonPhrase as c}from"http-status-codes";import{p as m}from"../packem_shared/add-status-code-to-response-Dc6Pvpeh.js";var g=Object.defineProperty,s=n((e,r)=>g(e,"name",{value:r,configurable:!0}),"n");const x=s((e={})=>async(r,d,t)=>{m(t,r),t.setHeader("content-type","text/html; charset=utf-8");const o=c(t.statusCode)||"Error",a=e.cspNonce?` nonce="${e.cspNonce}"`:"";if(e.errorPage){const i=typeof e.errorPage=="function"?await e.errorPage({error:r,reasonPhrase:o,request:d,response:t,statusCode:t.statusCode}):e.errorPage;if(i){t.end(i);return}}t.end(String.raw`<!DOCTYPE html>
2
2
  <html lang="en">
3
3
  <head>
4
4
  <meta charset="utf-8">
@@ -1 +1 @@
1
- var p=Object.defineProperty;var a=(e,r)=>p(e,"name",{value:r,configurable:!0});import{getReasonPhrase as u}from"http-status-codes";import{a as f}from"../packem_shared/add-status-code-to-response-BE6paXjR.js";import{s as n}from"../packem_shared/send-json-Cedv8-Bt.js";import{a as i}from"../packem_shared/set-error-headers-DT9rVGtW.js";var g=Object.defineProperty,l=a((e,r)=>g(e,"name",{value:r,configurable:!0}),"n");const h=l((e={})=>async(r,m,s)=>{f(s,r),i(s,r);const{statusCode:o}=s,t=u(o)||"An error occurred";if(e.formatter){const c=await e.formatter({error:r,reasonPhrase:t,request:m,response:s,statusCode:o});n(s,c);return}const{expose:d}=r;n(s,{message:r.message||t,error:t,statusCode:o,...d?{stack:r.stack}:{}})},"jsonErrorHandler");export{h as jsonErrorHandler};
1
+ var f=Object.defineProperty;var a=(e,r)=>f(e,"name",{value:r,configurable:!0});import{getReasonPhrase as i}from"http-status-codes";import{p as u}from"../packem_shared/add-status-code-to-response-Dc6Pvpeh.js";import{s as n}from"../packem_shared/send-json-DfdjS9Xp.js";import{a as d}from"../packem_shared/set-error-headers-DT9rVGtW.js";var g=Object.defineProperty,l=a((e,r)=>g(e,"name",{value:r,configurable:!0}),"n");const h=l((e={})=>async(r,m,s)=>{u(s,r),d(s,r);const{statusCode:t}=s,o=i(t)||"An error occurred";if(e.formatter){const p=await e.formatter({error:r,reasonPhrase:o,request:m,response:s,statusCode:t});n(s,p);return}const{expose:c}=r;n(s,{message:r.message||o,error:o,statusCode:t,...c?{stack:r.stack}:{}})},"jsonErrorHandler");export{h as jsonErrorHandler};
@@ -1 +1 @@
1
- var u=Object.defineProperty;var i=(e,s)=>u(e,"name",{value:s,configurable:!0});import{isHttpError as f}from"http-errors";import{getReasonPhrase as n}from"http-status-codes";import a from"ts-japi";import{a as l}from"../packem_shared/add-status-code-to-response-BE6paXjR.js";import{s as t}from"../packem_shared/send-json-Cedv8-Bt.js";import{a as c}from"../packem_shared/set-error-headers-DT9rVGtW.js";var g=Object.defineProperty,C=i((e,s)=>g(e,"name",{value:s,configurable:!0}),"n");const d="An error occurred",H=C((e,s,r)=>{if(l(r,e),c(r,e),e instanceof a.JapiError||a.JapiError.isLikeJapiError(e)){const o=new a.ErrorSerializer;t(r,o.serialize(e))}else if(f(e)){const o="statusCode"in e&&typeof e.statusCode=="number"?e.statusCode:"status"in e&&typeof e.status=="number"?e.status:r.statusCode,m="title"in e&&typeof e.title=="string"?e.title:void 0,p="message"in e&&typeof e.message=="string"?e.message:"";t(r,{errors:[{code:o??r.statusCode,title:m||n(o)||d,detail:p}]})}else{const{message:o}=e;t(r,{errors:[{code:"500",title:n(r.statusCode)||d,detail:o}]})}},"jsonapiErrorHandler");export{H as default};
1
+ var l=Object.defineProperty;var a=(e,o)=>l(e,"name",{value:o,configurable:!0});import{isHttpError as u}from"http-errors";import{getReasonPhrase as n}from"http-status-codes";import i from"ts-japi";import{p as d}from"../packem_shared/add-status-code-to-response-Dc6Pvpeh.js";import{s as t}from"../packem_shared/send-json-DfdjS9Xp.js";import{a as c}from"../packem_shared/set-error-headers-DT9rVGtW.js";var g=Object.defineProperty,m=a((e,o)=>g(e,"name",{value:o,configurable:!0}),"i");const E=m((e,o)=>"statusCode"in e&&typeof e.statusCode=="number"?e.statusCode:"status"in e&&typeof e.status=="number"?e.status:o,"resolveStatusCode"),H=m((e,o,r)=>{if(d(r,e),c(r,e),e instanceof i.JapiError||i.JapiError.isLikeJapiError(e)){const s=new i.ErrorSerializer;t(r,s.serialize(e))}else if(u(e)){const s=E(e,r.statusCode),p="title"in e&&typeof e.title=="string"?e.title:void 0,f="message"in e&&typeof e.message=="string"?e.message:"";t(r,{errors:[{code:s,title:p??n(s),detail:f}]})}else{const{message:s}=e;t(r,{errors:[{code:"500",title:n(r.statusCode),detail:s}]})}},"jsonapiErrorHandler");export{H as default};
@@ -1,5 +1,6 @@
1
1
  import type { IncomingMessage, ServerResponse } from "node:http";
2
2
  import type { ErrorHandler } from "./types.d.d.ts";
3
+ declare const jsonpErrorHandler: (options?: JsonpErrorHandlerOptions) => ErrorHandler;
3
4
  export type JsonpErrorBody = Record<string, unknown> | unknown[];
4
5
  export type JsonpErrorFormatter = (parameters: {
5
6
  error: Error;
@@ -12,4 +13,4 @@ export type JsonpErrorHandlerOptions = {
12
13
  callbackParamName?: string;
13
14
  formatter?: JsonpErrorFormatter;
14
15
  };
15
- export declare const jsonpErrorHandler: (options?: JsonpErrorHandlerOptions) => ErrorHandler;
16
+ export { jsonpErrorHandler };
@@ -1 +1 @@
1
- var i=Object.defineProperty;var n=(e,a)=>i(e,"name",{value:a,configurable:!0});import{getReasonPhrase as f}from"http-status-codes";import{a as u}from"../packem_shared/add-status-code-to-response-BE6paXjR.js";import{a as h}from"../packem_shared/set-error-headers-DT9rVGtW.js";var g=Object.defineProperty,b=n((e,a)=>g(e,"name",{value:a,configurable:!0}),"c");const k="callback",C=b((e={})=>async(a,c,t)=>{u(t,a),h(t,a);const{statusCode:r}=t,s=f(r)||"An error occurred",l=new URL(c.url??"http://localhost","http://localhost"),p=e.callbackParamName||k,m=l.searchParams.get(p)||"callback";let o;if(e.formatter)o=await e.formatter({error:a,reasonPhrase:s,request:c,response:t,statusCode:r});else{const{expose:d}=a;o={message:a.message||s,error:s,statusCode:r,...d?{stack:a.stack}:{}}}t.setHeader("content-type","application/javascript; charset=utf-8"),t.end(`${m}(${JSON.stringify(o)});`)},"jsonpErrorHandler");export{C as jsonpErrorHandler};
1
+ var f=Object.defineProperty;var l=(t,a)=>f(t,"name",{value:a,configurable:!0});import{getReasonPhrase as d}from"http-status-codes";import{p as u}from"../packem_shared/add-status-code-to-response-Dc6Pvpeh.js";import{a as h}from"../packem_shared/set-error-headers-DT9rVGtW.js";var g=Object.defineProperty,k=l((t,a)=>g(t,"name",{value:a,configurable:!0}),"c");const b="callback",$=k((t={})=>async(a,c,e)=>{u(e,a),h(e,a);const{statusCode:r}=e,s=d(r),n=new URL(c.url??"http://localhost","http://localhost"),p=t.callbackParamName??b,m=n.searchParams.get(p)??"callback";let o;if(t.formatter)o=await t.formatter({error:a,reasonPhrase:s,request:c,response:e,statusCode:r});else{const{expose:i}=a;o={message:a.message||s,error:s,statusCode:r,...i?{stack:a.stack}:{}}}e.setHeader("content-type","application/javascript; charset=utf-8"),e.end(`${m}(${JSON.stringify(o)});`)},"jsonpErrorHandler");export{$ as jsonpErrorHandler};
@@ -1 +1 @@
1
- var c=Object.defineProperty;var i=(e,o)=>c(e,"name",{value:o,configurable:!0});import{isHttpError as y}from"http-errors";import{getReasonPhrase as p}from"http-status-codes";import{a as b}from"../packem_shared/add-status-code-to-response-BE6paXjR.js";import{s as n}from"../packem_shared/send-json-Cedv8-Bt.js";import{a as C}from"../packem_shared/set-error-headers-DT9rVGtW.js";var v=Object.defineProperty,g=i((e,o)=>v(e,"name",{value:o,configurable:!0}),"i");const d="about:blank",u="An error occurred",R=g((e,o,t)=>{const{message:a,stack:r}=e;if(y(e)){const l="expose"in e?e.expose:void 0,s="statusCode"in e&&typeof e.statusCode=="number"?e.statusCode:"status"in e&&typeof e.status=="number"?e.status:t.statusCode,m="title"in e&&typeof e.title=="string"?e.title:void 0,f="type"in e&&typeof e.type=="string"?e.type:void 0;t.statusCode=s,C(t,e),n(t,{type:f||d,title:m||p(s)||u,status:s,detail:a,...l?{trace:r}:{}},"application/problem+json")}else b(t,e),n(t,{type:d,title:p(t.statusCode)||u,status:t.statusCode,detail:a,...e.expose?{trace:r}:{}},"application/problem+json")},"problemErrorHandler");export{R as default};
1
+ var y=Object.defineProperty;var i=(e,o)=>y(e,"name",{value:o,configurable:!0});import{isHttpError as c}from"http-errors";import{getReasonPhrase as p}from"http-status-codes";import{p as b}from"../packem_shared/add-status-code-to-response-Dc6Pvpeh.js";import{s as n}from"../packem_shared/send-json-DfdjS9Xp.js";import{a as C}from"../packem_shared/set-error-headers-DT9rVGtW.js";var v=Object.defineProperty,l=i((e,o)=>v(e,"name",{value:o,configurable:!0}),"o");const u="about:blank",g=l((e,o)=>"statusCode"in e&&typeof e.statusCode=="number"?e.statusCode:"status"in e&&typeof e.status=="number"?e.status:o,"resolveStatusCode"),h=l((e,o,t)=>{const{message:a,stack:r}=e;if(c(e)){const m="expose"in e?e.expose:void 0,s=g(e,t.statusCode),d="title"in e&&typeof e.title=="string"?e.title:void 0,f="type"in e&&typeof e.type=="string"?e.type:void 0;t.statusCode=s,C(t,e),n(t,{type:f??u,title:d??p(s),status:s,detail:a,...m?{trace:r}:{}},"application/problem+json")}else b(t,e),n(t,{type:u,title:p(t.statusCode),status:t.statusCode,detail:a,...e.expose?{trace:r}:{}},"application/problem+json")},"problemErrorHandler");export{h as default};
@@ -1,3 +1,3 @@
1
- var f=Object.defineProperty;var d=(r,e)=>f(r,"name",{value:e,configurable:!0});import{getReasonPhrase as i}from"http-status-codes";import{a as u}from"../packem_shared/add-status-code-to-response-BE6paXjR.js";import{a as l}from"../packem_shared/set-error-headers-DT9rVGtW.js";var x=Object.defineProperty,v=d((r,e)=>x(r,"name",{value:e,configurable:!0}),"m");const E=v((r={})=>async(e,c,t)=>{u(t,e),l(t,e);const{statusCode:o}=t,a=i(o)||"Error";if(t.setHeader("content-type","text/plain; charset=utf-8"),r.formatter){const p=await r.formatter({error:e,reasonPhrase:a,request:c,response:t,statusCode:o});t.end(p);return}const s=e.message||a,{expose:m}=e,n=m?e.stack:void 0;t.end(n?`${s}
1
+ var f=Object.defineProperty;var c=(t,e)=>f(t,"name",{value:e,configurable:!0});import{getReasonPhrase as i}from"http-status-codes";import{p as u}from"../packem_shared/add-status-code-to-response-Dc6Pvpeh.js";import{a as l}from"../packem_shared/set-error-headers-DT9rVGtW.js";var x=Object.defineProperty,v=c((t,e)=>x(t,"name",{value:e,configurable:!0}),"m");const E=v((t={})=>async(e,m,r)=>{u(r,e),l(r,e);const{statusCode:o}=r,a=i(o)||"Error";if(r.setHeader("content-type","text/plain; charset=utf-8"),t.formatter){const d=await t.formatter({error:e,reasonPhrase:a,request:m,response:r,statusCode:o});r.end(d);return}const s=e.message||a,{expose:p}=e,n=p?e.stack:void 0;r.end(n?`${s}
2
2
 
3
3
  ${n}`:s)},"textErrorHandler");export{E as textErrorHandler};
@@ -1,2 +1,3 @@
1
1
  import type { ServerResponse } from "node:http";
2
- export declare const addStatusCodeToResponse: (response: ServerResponse, error: unknown) => void;
2
+ declare const addStatusCodeToResponse: (response: ServerResponse, error: unknown) => void;
3
+ export default addStatusCodeToResponse;
@@ -1,8 +1,9 @@
1
1
  import type { ServerResponse } from "node:http";
2
2
  /**
3
- * Send `JSON` object
3
+ * Sends a JSON object as the response body.
4
4
  * @param response response object
5
5
  * @param jsonBody of data
6
6
  * @param contentType optional content-type header value
7
7
  */
8
- export declare const sendJson: (response: ServerResponse, jsonBody: unknown, contentType?: string) => void;
8
+ declare const sendJson: (response: ServerResponse, jsonBody: unknown, contentType?: string) => void;
9
+ export default sendJson;
@@ -1 +1 @@
1
- var c=Object.defineProperty;var l=(t,e)=>c(t,"name",{value:e,configurable:!0});import{getReasonPhrase as p}from"http-status-codes";import{toXML as u}from"jstoxml";import{a as d}from"../packem_shared/add-status-code-to-response-BE6paXjR.js";import{a as X}from"../packem_shared/set-error-headers-DT9rVGtW.js";var f=Object.defineProperty,b=l((t,e)=>f(t,"name",{value:e,configurable:!0}),"l");const h=b((t={})=>async(e,n,o)=>{d(o,e),X(o,e);const{statusCode:r}=o,a=p(r)||"An error occurred";let s;if(t.formatter)s=await t.formatter({error:e,reasonPhrase:a,request:n,response:o,statusCode:r});else{const{expose:i}=e;s={error:{statusCode:r,name:a,message:e.message||a,...i?{stack:e.stack}:{}}}}const m=u(s,{header:t.toXml?.header??t.xmlHeader??!0,indent:t.toXml?.indent??" ",...t.toXml?.attributeReplacements?{attributeReplacements:t.toXml.attributeReplacements}:{},...t.toXml?.attributeFilter?{attributeFilter:t.toXml.attributeFilter}:{},...t.toXml?.attributeExplicitTrue===void 0?{}:{attributeExplicitTrue:t.toXml.attributeExplicitTrue},...t.toXml?.contentMap?{contentMap:t.toXml.contentMap}:{},...t.toXml?.contentReplacements?{contentReplacements:t.toXml.contentReplacements}:{},...t.toXml?.selfCloseTags===void 0?{}:{selfCloseTags:t.toXml.selfCloseTags}});o.setHeader("content-type","application/xml; charset=utf-8"),o.end(m)},"xmlErrorHandler");export{h as xmlErrorHandler};
1
+ var c=Object.defineProperty;var s=(t,e)=>c(t,"name",{value:e,configurable:!0});import{getReasonPhrase as p}from"http-status-codes";import{toXML as u}from"jstoxml";import{p as d}from"../packem_shared/add-status-code-to-response-Dc6Pvpeh.js";import{a as X}from"../packem_shared/set-error-headers-DT9rVGtW.js";var f=Object.defineProperty,b=s((t,e)=>f(t,"name",{value:e,configurable:!0}),"l");const h=b((t={})=>async(e,n,o)=>{d(o,e),X(o,e);const{statusCode:r}=o,a=p(r)||"An error occurred";let l;if(t.formatter)l=await t.formatter({error:e,reasonPhrase:a,request:n,response:o,statusCode:r});else{const{expose:i}=e;l={error:{statusCode:r,name:a,message:e.message||a,...i?{stack:e.stack}:{}}}}const m=u(l,{header:t.toXml?.header??t.xmlHeader??!0,indent:t.toXml?.indent??" ",...t.toXml?.attributeReplacements?{attributeReplacements:t.toXml.attributeReplacements}:{},...t.toXml?.attributeFilter?{attributeFilter:t.toXml.attributeFilter}:{},...t.toXml?.attributeExplicitTrue===void 0?{}:{attributeExplicitTrue:t.toXml.attributeExplicitTrue},...t.toXml?.contentMap?{contentMap:t.toXml.contentMap}:{},...t.toXml?.contentReplacements?{contentReplacements:t.toXml.contentReplacements}:{},...t.toXml?.selfCloseTags===void 0?{}:{selfCloseTags:t.toXml.selfCloseTags}});o.setHeader("content-type","application/xml; charset=utf-8"),o.end(m)},"xmlErrorHandler");export{h as xmlErrorHandler};
@@ -4,5 +4,5 @@ declare const fetchHandler: (error: Error, options?: HtmlErrorHandlerOptions & {
4
4
  extraHandlers?: FetchErrorHandlers;
5
5
  onError?: (error: Error, request: Request) => void | Promise<void>;
6
6
  showTrace?: boolean;
7
- }) => Promise<(request: Request) => Promise<Response>>;
7
+ }) => (request: Request) => Promise<Response>;
8
8
  export default fetchHandler;
@@ -1 +1 @@
1
- var b=Object.defineProperty;var c=(r,e)=>b(r,"name",{value:e,configurable:!0});import{jsonErrorHandler as g}from"../../error-handler/json-error-handler.js";import w from"../../error-handler/jsonapi-error-handler.js";import{jsonpErrorHandler as y}from"../../error-handler/jsonp-error-handler.js";import u from"../../error-handler/problem-error-handler.js";import{textErrorHandler as H}from"../../error-handler/text-error-handler.js";import{xmlErrorHandler as v}from"../../error-handler/xml-error-handler.js";import{htmlErrorHandler as L}from"../../error-handler/html-error-handler.js";var j=Object.defineProperty,h=c((r,e)=>j(r,"name",{value:e,configurable:!0}),"a$1");class x{static{c(this,"j")}static{h(this,"MockServerResponse")}statusCode=200;headers={};_body="";setHeader(e,s){this.headers[e.toLowerCase()]=s}getHeader(e){return this.headers[e.toLowerCase()]}getHeaders(){return{...this.headers}}writeHead(e){this.statusCode=e}write(e){this._body+=e.toString()}end(e){e&&(this._body+=e.toString())}flushHeaders(){}}const k=h(r=>{if(!r)return"text/html";const e=r.toLowerCase();return e.includes("text/html")?"text/html":e.includes("application/vnd.api+json")?"application/vnd.api+json":e.includes("application/problem+json")?"application/problem+json":e.includes("application/json")?"application/json":e.includes("text/plain")?"text/plain":e.includes("application/javascript")||e.includes("text/javascript")?"application/javascript":e.includes("application/xml")||e.includes("text/xml")?"application/xml":"text/html"},"negotiateContentType"),d=h(r=>async(e,s)=>{const a={headers:Object.fromEntries(s.headers.entries()),method:s.method,url:s.url},i=new x;await r(e,a,i);const o={};for(const[l,n]of Object.entries(i.headers))o[l]=Array.isArray(n)?n.join(", "):String(n);return new Response(i._body,{headers:o,status:i.statusCode})},"adaptErrorHandlerToFetch"),C=h((r,e,s)=>async(a,i)=>{const o=i.headers.get("accept"),l=k(o);let n=s||d(u);if(l==="text/html"&&s)n=s;else switch(l){case"application/javascript":{n=d(y());break}case"application/json":{n=d(g());break}case"application/problem+json":{n=d(u);break}case"application/vnd.api+json":{n=d(w);break}case"application/xml":{n=d(v());break}case"text/plain":{n=d(H());break}}for(const{handler:p,regex:m}of r){const f=o??"";if(m.test(f)){n=p;break}}return a.expose=e,n(a,i)},"createFetchNegotiatedErrorHandler");var E=Object.defineProperty,t=c((r,e)=>E(r,"name",{value:e,configurable:!0}),"e");class S{static{c(this,"b")}static{t(this,"MockServerResponse")}statusCode=200;statusMessage="";headers={};headersSent=!1;writable=!0;finished=!1;writableEnded=!1;writableFinished=!1;writableHighWaterMark=16384;writableLength=0;destroyed=!1;writableCorked=0;readable=!1;readableHighWaterMark=16384;readableLength=0;errored=null;closed=!1;readableAborted=!1;readableDidRead=!1;readableEncoding=null;readableEnded=!1;readableFlowing=null;_events;_eventsCount=0;_maxListeners;body="";sendDate=!0;strictContentLength=!1;chunkedEncoding=!1;shouldKeepAlive=!0;useChunkedEncodingByDefault=!0;_hasBody=!0;_trailer="";connection=null;socket=null;setHeader(e,s){return this.headers[e.toLowerCase()]=s,this}getHeader(e){return this.headers[e.toLowerCase()]}getHeaders(){return{...this.headers}}getHeaderNames(){return Object.keys(this.headers)}hasHeader(e){return e.toLowerCase()in this.headers}removeHeader(e){return delete this.headers[e.toLowerCase()],this}writeHead(e,s,a){return this.statusCode=e,typeof s=="string"&&(this.statusMessage=s),typeof s=="object"&&(a=s),a&&Object.assign(this.headers,a),this}write(e){return this.body+=e.toString(),!0}end(e,s,a){return e&&(this.body+=e.toString()),this.finished=!0,this}flushHeaders(){this.headersSent=!0}addListener=t(()=>this,"addListener");on=t(()=>this,"on");once=t(()=>this,"once");removeListener=t(()=>this,"removeListener");off=t(()=>this,"off");removeAllListeners=t(()=>this,"removeAllListeners");setMaxListeners=t(()=>this,"setMaxListeners");getMaxListeners=t(()=>10,"getMaxListeners");listeners=t(()=>[],"listeners");rawListeners=t(()=>[],"rawListeners");emit=t(()=>!1,"emit");eventNames=t(()=>[],"eventNames");listenerCount=t(()=>0,"listenerCount");prependListener=t(()=>this,"prependListener");prependOnceListener=t(()=>this,"prependOnceListener");cork=t(()=>{},"cork");uncork=t(()=>{},"uncork");destroy=t(()=>this,"destroy");read=t(()=>null,"read");setEncoding=t(()=>this,"setEncoding");pause=t(()=>this,"pause");resume=t(()=>this,"resume");isPaused=t(()=>!1,"isPaused");destroySoon=t(()=>this,"destroySoon");pipe=t(()=>({}),"pipe");unpipe=t(()=>this,"unpipe");unshift=t(()=>{},"unshift");wrap=t(()=>this,"wrap");setTimeout=t(()=>this,"setTimeout");assignSocket=t(()=>{},"assignSocket");detachSocket=t(()=>{},"detachSocket");writeContinue=t(()=>{},"writeContinue");writeEarlyHints=t(()=>{},"writeEarlyHints")}const M=t((r={})=>{const e=L(r);return async(s,a)=>{const i={headers:Object.fromEntries(a.headers.entries()),method:a.method,url:a.url},o=new S;await e(s,i,o);const l=o.getHeader("content-type")||"text/html; charset=utf-8";return new Response(o.body,{headers:{"content-type":l,...o.headers},status:o.statusCode})}},"fetchHtmlErrorHandler");var O=Object.defineProperty,_=c((r,e)=>O(r,"name",{value:e,configurable:!0}),"t");const B=_(async(r,e={})=>{const s=M(e),a=C(e.extraHandlers??[],e.showTrace??!0,s);return async i=>(e?.onError&&await e.onError(r,i),a(r,i))},"fetchHandler");export{B as default};
1
+ var b=Object.defineProperty;var c=(r,e)=>b(r,"name",{value:e,configurable:!0});import{jsonErrorHandler as g}from"../../error-handler/json-error-handler.js";import w from"../../error-handler/jsonapi-error-handler.js";import{jsonpErrorHandler as v}from"../../error-handler/jsonp-error-handler.js";import p from"../../error-handler/problem-error-handler.js";import{textErrorHandler as y}from"../../error-handler/text-error-handler.js";import{xmlErrorHandler as H}from"../../error-handler/xml-error-handler.js";import{htmlErrorHandler as j}from"../../error-handler/html-error-handler.js";var x=Object.defineProperty,h=c((r,e)=>x(r,"name",{value:e,configurable:!0}),"i");class L{static{c(this,"x")}static{h(this,"MockServerResponse")}statusCode=200;headers={};responseBody="";setHeader(e,s){this.headers[e.toLowerCase()]=s}getHeader(e){return this.headers[e.toLowerCase()]}getHeaders(){return{...this.headers}}writeHead(e){this.statusCode=e}write(e){this.responseBody+=e.toString()}end(e){e&&(this.responseBody+=e.toString())}flushHeaders(){}}const k=h(r=>{if(!r)return"text/html";const e=r.toLowerCase();return e.includes("text/html")?"text/html":e.includes("application/vnd.api+json")?"application/vnd.api+json":e.includes("application/problem+json")?"application/problem+json":e.includes("application/json")?"application/json":e.includes("text/plain")?"text/plain":e.includes("application/javascript")||e.includes("text/javascript")?"application/javascript":e.includes("application/xml")||e.includes("text/xml")?"application/xml":"text/html"},"negotiateContentType"),d=h(r=>async(e,s)=>{const n={headers:Object.fromEntries(s.headers.entries()),method:s.method,url:s.url},a=new L;await r(e,n,a);const o={};for(const[l,i]of Object.entries(a.headers))o[l]=Array.isArray(i)?i.join(", "):String(i);return new Response(a.responseBody,{headers:o,status:a.statusCode})},"adaptErrorHandlerToFetch"),E=h((r,e,s)=>async(n,a)=>{const o=a.headers.get("accept"),l=k(o);let i=s??d(p);if(l==="text/html"&&s)i=s;else switch(l){case"application/javascript":{i=d(v());break}case"application/json":{i=d(g());break}case"application/problem+json":{i=d(p);break}case"application/vnd.api+json":{i=d(w);break}case"application/xml":{i=d(H());break}case"text/plain":{i=d(y());break}}for(const{handler:u,regex:m}of r){const f=o??"";if(m.test(f)){i=u;break}}return n.expose=e,i(n,a)},"createFetchNegotiatedErrorHandler");var C=Object.defineProperty,t=c((r,e)=>C(r,"name",{value:e,configurable:!0}),"e");class S{static{c(this,"d")}static{t(this,"MockServerResponse")}statusCode=200;statusMessage="";headers={};headersSent=!1;writable=!0;finished=!1;writableEnded=!1;writableFinished=!1;writableHighWaterMark=16384;writableLength=0;destroyed=!1;writableCorked=0;readable=!1;readableHighWaterMark=16384;readableLength=0;errored=void 0;closed=!1;readableAborted=!1;readableDidRead=!1;readableEncoding=void 0;readableEnded=!1;readableFlowing=void 0;body="";sendDate=!0;strictContentLength=!1;chunkedEncoding=!1;shouldKeepAlive=!0;useChunkedEncodingByDefault=!0;connection=void 0;socket=void 0;setHeader(e,s){return this.headers[e.toLowerCase()]=s,this}getHeader(e){return this.headers[e.toLowerCase()]}getHeaders(){return{...this.headers}}getHeaderNames(){return Object.keys(this.headers)}hasHeader(e){return e.toLowerCase()in this.headers}removeHeader(e){return delete this.headers[e.toLowerCase()],this}writeHead(e,s,n){this.statusCode=e;let a=n;return typeof s=="string"&&(this.statusMessage=s),typeof s=="object"&&(a=s),a&&Object.assign(this.headers,a),this}write(e){return this.body+=e.toString(),!0}end(e,s,n){return e&&(this.body+=e.toString()),this.finished=!0,this}flushHeaders(){this.headersSent=!0}addListener=t(()=>this,"addListener");on=t(()=>this,"on");once=t(()=>this,"once");removeListener=t(()=>this,"removeListener");off=t(()=>this,"off");removeAllListeners=t(()=>this,"removeAllListeners");setMaxListeners=t(()=>this,"setMaxListeners");getMaxListeners=t(()=>10,"getMaxListeners");listeners=t(()=>[],"listeners");rawListeners=t(()=>[],"rawListeners");emit=t(()=>!1,"emit");eventNames=t(()=>[],"eventNames");listenerCount=t(()=>0,"listenerCount");prependListener=t(()=>this,"prependListener");prependOnceListener=t(()=>this,"prependOnceListener");cork=t(()=>{},"cork");uncork=t(()=>{},"uncork");destroy=t(()=>this,"destroy");read=t(()=>{},"read");setEncoding=t(()=>this,"setEncoding");pause=t(()=>this,"pause");resume=t(()=>this,"resume");isPaused=t(()=>!1,"isPaused");destroySoon=t(()=>this,"destroySoon");pipe=t(()=>({}),"pipe");unpipe=t(()=>this,"unpipe");unshift=t(()=>{},"unshift");wrap=t(()=>this,"wrap");setTimeout=t(()=>this,"setTimeout");assignSocket=t(()=>{},"assignSocket");detachSocket=t(()=>{},"detachSocket");writeContinue=t(()=>{},"writeContinue");writeEarlyHints=t(()=>{},"writeEarlyHints")}const M=t((r={})=>{const e=j(r);return async(s,n)=>{const a={headers:Object.fromEntries(n.headers.entries()),method:n.method,url:n.url},o=new S;await e(s,a,o);const l=o.getHeader("content-type")??"text/html; charset=utf-8";return new Response(o.body,{headers:{"content-type":l,...o.headers},status:o.statusCode})}},"fetchHtmlErrorHandler");var O=Object.defineProperty,A=c((r,e)=>O(r,"name",{value:e,configurable:!0}),"t");const K=A((r,e={})=>{const s=M(e),n=E(e.extraHandlers??[],e.showTrace??!0,s);return async a=>(e.onError&&await e.onError(r,a),n(r,a))},"fetchHandler");export{K as default};
@@ -5,5 +5,5 @@ declare const nodeHandler: (error: Error, options?: HtmlErrorHandlerOptions & {
5
5
  extraHandlers?: ErrorHandlers;
6
6
  onError?: (error: Error, request: IncomingMessage, response: ServerResponse) => void | Promise<void>;
7
7
  showTrace?: boolean;
8
- }) => Promise<(request: IncomingMessage, response: ServerResponse) => Promise<void>>;
8
+ }) => (request: IncomingMessage, response: ServerResponse) => Promise<void>;
9
9
  export default nodeHandler;
@@ -1 +1 @@
1
- var s=Object.defineProperty;var o=(a,r)=>s(a,"name",{value:r,configurable:!0});import c from"../../packem_shared/createNegotiatedErrorHandler-BLks0_Ak.js";import{htmlErrorHandler as m}from"../../error-handler/html-error-handler.js";var d=Object.defineProperty,i=o((a,r)=>d(a,"name",{value:r,configurable:!0}),"s");const v=i(async(a,r={})=>{const n=m(r),l=c(r.extraHandlers??[],r.showTrace??!0,n);return async(e,t)=>{r?.onError&&await r.onError(a,e,t),await l(a,e,t)}},"nodeHandler");export{v as default};
1
+ var i=Object.defineProperty;var o=(a,r)=>i(a,"name",{value:r,configurable:!0});import l from"../../packem_shared/createNegotiatedErrorHandler-b0kjXpZ3.js";import{htmlErrorHandler as s}from"../../error-handler/html-error-handler.js";var c=Object.defineProperty,m=o((a,r)=>c(a,"name",{value:r,configurable:!0}),"t");const v=m((a,r={})=>{const n=s(r),d=l(r.extraHandlers??[],r.showTrace??!0,n);return async(e,t)=>{r.onError&&await r.onError(a,e,t),await d(a,e,t)}},"nodeHandler");export{v as default};
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{default as e}from"./packem_shared/createNegotiatedErrorHandler-BLks0_Ak.js";import{htmlErrorHandler as t}from"./error-handler/html-error-handler.js";import{jsonErrorHandler as d}from"./error-handler/json-error-handler.js";import{default as m}from"./error-handler/jsonapi-error-handler.js";import{jsonpErrorHandler as p}from"./error-handler/jsonp-error-handler.js";import{default as E}from"./error-handler/problem-error-handler.js";import{textErrorHandler as s}from"./error-handler/text-error-handler.js";import{xmlErrorHandler as u}from"./error-handler/xml-error-handler.js";export{e as createNegotiatedErrorHandler,t as htmlErrorHandler,d as jsonErrorHandler,m as jsonapiErrorHandler,p as jsonpErrorHandler,E as problemErrorHandler,s as textErrorHandler,u as xmlErrorHandler};
1
+ import{default as e}from"./packem_shared/createNegotiatedErrorHandler-b0kjXpZ3.js";import{htmlErrorHandler as t}from"./error-handler/html-error-handler.js";import{jsonErrorHandler as d}from"./error-handler/json-error-handler.js";import{default as m}from"./error-handler/jsonapi-error-handler.js";import{jsonpErrorHandler as p}from"./error-handler/jsonp-error-handler.js";import{default as E}from"./error-handler/problem-error-handler.js";import{textErrorHandler as s}from"./error-handler/text-error-handler.js";import{xmlErrorHandler as u}from"./error-handler/xml-error-handler.js";export{e as createNegotiatedErrorHandler,t as htmlErrorHandler,d as jsonErrorHandler,m as jsonapiErrorHandler,p as jsonpErrorHandler,E as problemErrorHandler,s as textErrorHandler,u as xmlErrorHandler};
@@ -0,0 +1 @@
1
+ var a=Object.defineProperty;var r=(e,t)=>a(e,"name",{value:t,configurable:!0});import{StatusCodes as u}from"http-status-codes";var d=Object.defineProperty,n=r((e,t)=>d(e,"name",{value:t,configurable:!0}),"s");const i=n((e,t)=>{const o=t,s=Number(o.statusCode??o.status);if(Number.isInteger(s)&&s>=400&&s<=599){e.statusCode=s;return}e.statusCode<400&&(e.statusCode=u.INTERNAL_SERVER_ERROR)},"addStatusCodeToResponse");export{i as p};
@@ -1 +1 @@
1
- var j=Object.defineProperty;var c=(r,e)=>j(r,"name",{value:e,configurable:!0});import{Accepts as d}from"@tinyhttp/accepts";import{jsonErrorHandler as b}from"../error-handler/json-error-handler.js";import v from"../error-handler/jsonapi-error-handler.js";import{jsonpErrorHandler as k}from"../error-handler/jsonp-error-handler.js";import l from"../error-handler/problem-error-handler.js";import{textErrorHandler as E}from"../error-handler/text-error-handler.js";import{xmlErrorHandler as h}from"../error-handler/xml-error-handler.js";var y=Object.defineProperty,H=c((r,e)=>y(r,"name",{value:e,configurable:!0}),"i");const q=H((r,e,t)=>async(p,o,s)=>{const n=new d(o).type(["text/html","application/vnd.api+json","application/problem+json","application/json","text/plain","application/javascript","text/javascript","application/xml","text/xml"]);let a=t||l;if(n==="text/html"&&t)a=t;else switch(n){case"application/javascript":case"text/javascript":{a=k();break}case"application/json":{a=b();break}case"application/problem+json":{a=l;break}case"application/vnd.api+json":{a=v;break}case"application/xml":case"text/xml":{a=h();break}case"text/plain":{a=E();break}}for(const{handler:m,regex:x}of r){const i=o.headers.accept??"",f=Array.isArray(i)?i.join(","):i;if(x.test(f)){a=m;break}}p.expose=e,await a(p,o,s)},"createNegotiatedErrorHandler");export{q as default};
1
+ var j=Object.defineProperty;var c=(r,e)=>j(r,"name",{value:e,configurable:!0});import{Accepts as d}from"@tinyhttp/accepts";import{jsonErrorHandler as b}from"../error-handler/json-error-handler.js";import v from"../error-handler/jsonapi-error-handler.js";import{jsonpErrorHandler as k}from"../error-handler/jsonp-error-handler.js";import s from"../error-handler/problem-error-handler.js";import{textErrorHandler as E}from"../error-handler/text-error-handler.js";import{xmlErrorHandler as g}from"../error-handler/xml-error-handler.js";var h=Object.defineProperty,y=c((r,e)=>h(r,"name",{value:e,configurable:!0}),"i");const q=y((r,e,t)=>async(p,o,l)=>{const n=new d(o).type(["text/html","application/vnd.api+json","application/problem+json","application/json","text/plain","application/javascript","text/javascript","application/xml","text/xml"]);let a=t??s;if(n==="text/html"&&t)a=t;else switch(n){case"application/javascript":case"text/javascript":{a=k();break}case"application/json":{a=b();break}case"application/problem+json":{a=s;break}case"application/vnd.api+json":{a=v;break}case"application/xml":case"text/xml":{a=g();break}case"text/plain":{a=E();break}}for(const{handler:m,regex:x}of r){const i=o.headers.accept??"",f=Array.isArray(i)?i.join(","):i;if(x.test(f)){a=m;break}}p.expose=e,await a(p,o,l)},"createNegotiatedErrorHandler");export{q as default};
@@ -0,0 +1 @@
1
+ var a=Object.defineProperty;var t=(e,n)=>a(e,"name",{value:n,configurable:!0});var o=Object.defineProperty,s=t((e,n)=>o(e,"name",{value:n,configurable:!0}),"n");const i=s((e,n,r="application/json; charset=utf-8")=>{e.setHeader("content-type",r),e.end(JSON.stringify(n))},"sendJson");export{i as s};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visulima/error-handler",
3
- "version": "2.0.0-alpha.10",
3
+ "version": "2.0.0-alpha.11",
4
4
  "description": "Error handlers for use in development and production environments.",
5
5
  "keywords": [
6
6
  "visulima",
@@ -134,15 +134,13 @@
134
134
  ],
135
135
  "dependencies": {
136
136
  "@tinyhttp/accepts": "^2.3.0",
137
- "@visulima/boxen": "3.0.0-alpha.8",
138
- "@visulima/error": "6.0.0-alpha.7",
137
+ "@visulima/boxen": "3.0.0-alpha.9",
138
+ "@visulima/error": "6.0.0-alpha.8",
139
139
  "http-errors": "^2.0.1",
140
140
  "http-status-codes": "^2.3.0",
141
141
  "jstoxml": "^7.1.0",
142
142
  "ts-japi": "^1.12.3"
143
143
  },
144
- "peerDependencies": {},
145
- "optionalDependencies": {},
146
144
  "engines": {
147
145
  "node": ">=22.13 <=25.x"
148
146
  },
@@ -1 +0,0 @@
1
- var r=Object.defineProperty;var o=(e,s)=>r(e,"name",{value:s,configurable:!0});import{StatusCodes as u}from"http-status-codes";var d=Object.defineProperty,n=o((e,s)=>d(e,"name",{value:s,configurable:!0}),"s");const i=n((e,s)=>{const a=s,t=Number(a.statusCode??a.status);if(Number.isInteger(t)&&t>=400&&t<=599){e.statusCode=t;return}e.statusCode<400&&(e.statusCode=u.INTERNAL_SERVER_ERROR)},"addStatusCodeToResponse");export{i as a};
@@ -1 +0,0 @@
1
- var s=Object.defineProperty;var t=(e,n)=>s(e,"name",{value:n,configurable:!0});var a=Object.defineProperty,o=t((e,n)=>a(e,"name",{value:n,configurable:!0}),"t");const i=o((e,n,r="application/json; charset=utf-8")=>{e.setHeader("content-type",r),e.end(JSON.stringify(n))},"sendJson");export{i as s};