@visulima/error-handler 1.0.3 → 1.0.5

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.
Files changed (34) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/LICENSE.md +13 -5
  3. package/README.md +24 -18
  4. package/dist/error-handler/html-error-handler.d.ts +4 -4
  5. package/dist/error-handler/html-error-handler.js +1 -1
  6. package/dist/error-handler/json-error-handler.d.ts +3 -3
  7. package/dist/error-handler/json-error-handler.js +1 -1
  8. package/dist/error-handler/jsonapi-error-handler.d.ts +1 -1
  9. package/dist/error-handler/jsonapi-error-handler.js +1 -1
  10. package/dist/error-handler/jsonp-error-handler.d.ts +3 -3
  11. package/dist/error-handler/jsonp-error-handler.js +1 -1
  12. package/dist/error-handler/problem-error-handler.d.ts +1 -1
  13. package/dist/error-handler/problem-error-handler.js +1 -1
  14. package/dist/error-handler/text-error-handler.d.ts +3 -3
  15. package/dist/error-handler/text-error-handler.js +2 -2
  16. package/dist/error-handler/xml-error-handler.d.ts +8 -8
  17. package/dist/error-handler/xml-error-handler.js +1 -1
  18. package/dist/handler/cli-handler.d.ts +2 -2
  19. package/dist/handler/cli-handler.js +2 -2
  20. package/dist/handler/http/fetch-handler.d.ts +2 -2
  21. package/dist/handler/http/fetch-handler.js +1 -1
  22. package/dist/handler/http/node-handler.d.ts +4 -4
  23. package/dist/handler/http/node-handler.js +1 -1
  24. package/dist/index.d.ts +6 -6
  25. package/dist/index.js +1 -1
  26. package/dist/packem_shared/add-status-code-to-response-BE6paXjR.js +1 -0
  27. package/dist/packem_shared/cliHandler-CFffArNH.js +1 -0
  28. package/dist/packem_shared/createNegotiatedErrorHandler-BLks0_Ak.js +1 -0
  29. package/dist/packem_shared/set-error-headers-DT9rVGtW.js +1 -0
  30. package/dist/packem_shared/{types.d-DLy8CCca.d.ts → types.d-BQZBUb3b.d.ts} +1 -4
  31. package/package.json +2 -2
  32. package/dist/packem_shared/add-status-code-to-response-DOfo6_g6.js +0 -1
  33. package/dist/packem_shared/createNegotiatedErrorHandler-ElYcOlsu.js +0 -1
  34. package/dist/packem_shared/set-error-headers-BWc7Sbh2.js +0 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,20 @@
1
+ ## @visulima/error-handler [1.0.5](https://github.com/visulima/visulima/compare/@visulima/error-handler@1.0.4...@visulima/error-handler@1.0.5) (2025-09-23)
2
+
3
+
4
+ ### Dependencies
5
+
6
+ * **@visulima/error:** upgraded to 4.6.2
7
+
8
+ ## @visulima/error-handler [1.0.4](https://github.com/visulima/visulima/compare/@visulima/error-handler@1.0.3...@visulima/error-handler@1.0.4) (2025-09-20)
9
+
10
+ ### Bug Fixes
11
+
12
+ * update error-handler configuration and improve code formatting ([0e9717c](https://github.com/visulima/visulima/commit/0e9717c6a642dde4c6d02974143d94597ed72dbd))
13
+
14
+ ### Miscellaneous Chores
15
+
16
+ * update package.json and pnpm-lock.yaml to include publint@0.3.12 and adjust build/test commands to exclude shared-utils ([1f7b3c0](https://github.com/visulima/visulima/commit/1f7b3c0381d77edfeec80ea1bf57b3469e929414))
17
+
1
18
  ## @visulima/error-handler [1.0.3](https://github.com/visulima/visulima/compare/@visulima/error-handler@1.0.2...@visulima/error-handler@1.0.3) (2025-09-19)
2
19
 
3
20
  ### Miscellaneous Chores
package/LICENSE.md CHANGED
@@ -23,11 +23,14 @@ SOFTWARE.
23
23
  <!-- DEPENDENCIES -->
24
24
 
25
25
  # Licenses of bundled dependencies
26
+
26
27
  The published @visulima/error-handler artifact additionally contains code with the following licenses:
27
28
  ISC, MIT
28
29
 
29
30
  # Bundled dependencies:
31
+
30
32
  ## depd
33
+
31
34
  License: MIT
32
35
  By: Douglas Christopher Wilson
33
36
  Repository: dougwilson/nodejs-depd
@@ -55,9 +58,10 @@ Repository: dougwilson/nodejs-depd
55
58
  > TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
56
59
  > SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
57
60
 
58
- ---------------------------------------
61
+ ---
59
62
 
60
63
  ## http-errors
64
+
61
65
  License: MIT
62
66
  By: Jonathan Ong, Alan Plum, Douglas Christopher Wilson
63
67
  Repository: jshttp/http-errors
@@ -85,9 +89,10 @@ Repository: jshttp/http-errors
85
89
  > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
86
90
  > THE SOFTWARE.
87
91
 
88
- ---------------------------------------
92
+ ---
89
93
 
90
94
  ## inherits
95
+
91
96
  License: ISC
92
97
  Repository: git://github.com/isaacs/inherits
93
98
 
@@ -107,9 +112,10 @@ Repository: git://github.com/isaacs/inherits
107
112
  > OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
108
113
  > PERFORMANCE OF THIS SOFTWARE.
109
114
 
110
- ---------------------------------------
115
+ ---
111
116
 
112
117
  ## setprototypeof
118
+
113
119
  License: ISC
114
120
  By: Wes Todd
115
121
  Repository: https://github.com/wesleytodd/setprototypeof.git
@@ -128,9 +134,10 @@ Repository: https://github.com/wesleytodd/setprototypeof.git
128
134
  > OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
129
135
  > CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
130
136
 
131
- ---------------------------------------
137
+ ---
132
138
 
133
139
  ## statuses
140
+
134
141
  License: MIT
135
142
  By: Douglas Christopher Wilson, Jonathan Ong
136
143
  Repository: jshttp/statuses
@@ -158,9 +165,10 @@ Repository: jshttp/statuses
158
165
  > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
159
166
  > THE SOFTWARE.
160
167
 
161
- ---------------------------------------
168
+ ---
162
169
 
163
170
  ## toidentifier
171
+
164
172
  License: MIT
165
173
  By: Douglas Christopher Wilson, Nick Baugh
166
174
  Repository: component/toidentifier
package/README.md CHANGED
@@ -62,7 +62,7 @@ const server = createServer(async (req, res) => {
62
62
  throw new Error("Boom!");
63
63
  } catch (error) {
64
64
  const handler = await httpHandler(error as Error, {
65
- showTrace: process.env.NODE_ENV !== "production"
65
+ showTrace: process.env.NODE_ENV !== "production",
66
66
  });
67
67
  return handler(req, res);
68
68
  }
@@ -85,7 +85,7 @@ app.get("/", async (req, res) => {
85
85
  throw new Error("Example error");
86
86
  } catch (error) {
87
87
  const handler = await httpHandler(error as Error, {
88
- showTrace: process.env.NODE_ENV !== "production"
88
+ showTrace: process.env.NODE_ENV !== "production",
89
89
  });
90
90
  return handler(req, res);
91
91
  }
@@ -110,7 +110,7 @@ app.get("/error", () => {
110
110
 
111
111
  app.onError(async (error, c) => {
112
112
  const handler = await fetchHandler(error as Error, {
113
- showTrace: process.env.NODE_ENV !== "production"
113
+ showTrace: process.env.NODE_ENV !== "production",
114
114
  });
115
115
  return handler(c.req.raw);
116
116
  });
@@ -130,7 +130,7 @@ export default {
130
130
  throw new Error("Boom");
131
131
  } catch (error) {
132
132
  const handler = await fetchHandler(error as Error, {
133
- showTrace: process.env.NODE_ENV !== "production"
133
+ showTrace: process.env.NODE_ENV !== "production",
134
134
  });
135
135
  return handler(request);
136
136
  }
@@ -147,7 +147,7 @@ Deno.serve(async (request: Request) => {
147
147
  throw new Error("Boom");
148
148
  } catch (error) {
149
149
  const handler = await fetchHandler(error as Error, {
150
- showTrace: process.env.NODE_ENV !== "production"
150
+ showTrace: process.env.NODE_ENV !== "production",
151
151
  });
152
152
  return handler(request);
153
153
  }
@@ -192,10 +192,12 @@ const handler = await httpHandler(error, {
192
192
  Node.js HTTP handler for Express, Connect, Fastify, Koa, and similar frameworks.
193
193
 
194
194
  **Parameters:**
195
+
195
196
  - `error: Error` - The error to handle
196
197
  - `options?: HtmlErrorHandlerOptions & { showTrace?: boolean; extraHandlers?: ErrorHandlers }`
197
198
 
198
199
  **Options:**
200
+
199
201
  - `showTrace?: boolean` - Include stack trace in responses (default: `true`)
200
202
  - `extraHandlers?: ErrorHandlers` - Custom handlers for specific Accept headers
201
203
  - `errorPage?: string | ((params) => string | Promise<string>)` - Custom HTML error page
@@ -207,10 +209,12 @@ Node.js HTTP handler for Express, Connect, Fastify, Koa, and similar frameworks.
207
209
  Fetch API handler for Cloudflare Workers, Deno, Bun, and other Fetch-based runtimes.
208
210
 
209
211
  **Parameters:**
212
+
210
213
  - `error: Error` - The error to handle
211
214
  - `options?: HtmlErrorHandlerOptions & { showTrace?: boolean; extraHandlers?: FetchErrorHandlers }`
212
215
 
213
216
  **Options:**
217
+
214
218
  - Same as `httpHandler` but uses `FetchErrorHandlers` for custom handlers
215
219
  - `onError?: (error, request, response) => void | Promise<void>` - Callback for custom error logging
216
220
 
@@ -228,13 +232,15 @@ type FetchErrorHandlers = {
228
232
  }[];
229
233
 
230
234
  type HtmlErrorHandlerOptions = {
231
- errorPage?: string | ((params: {
232
- error: Error;
233
- request: IncomingMessage;
234
- response: ServerResponse;
235
- reasonPhrase: string;
236
- statusCode: number;
237
- }) => string | Promise<string>);
235
+ errorPage?:
236
+ | string
237
+ | ((params: {
238
+ error: Error;
239
+ request: IncomingMessage;
240
+ response: ServerResponse;
241
+ reasonPhrase: string;
242
+ statusCode: number;
243
+ }) => string | Promise<string>);
238
244
  cspNonce?: string;
239
245
  onError?: (error: Error, request: IncomingMessage, response: ServerResponse) => void | Promise<void>;
240
246
  };
@@ -253,7 +259,7 @@ const server = createServer(async (req, res) => {
253
259
  throw new Error("Test error");
254
260
  } catch (error) {
255
261
  const handler = await httpHandler(error as Error, {
256
- showTrace: process.env.NODE_ENV !== "production"
262
+ showTrace: process.env.NODE_ENV !== "production",
257
263
  });
258
264
  return handler(req, res);
259
265
  }
@@ -275,7 +281,7 @@ const handler = await httpHandler(error, {
275
281
  <p>${error.message}</p>
276
282
  </body>
277
283
  </html>`,
278
- showTrace: false
284
+ showTrace: false,
279
285
  });
280
286
  ```
281
287
 
@@ -286,7 +292,7 @@ import httpHandler from "@visulima/error-handler/handler/http/node";
286
292
 
287
293
  const handler = await httpHandler(error, {
288
294
  cspNonce: "nonce-abc123", // Will be added to <style> tags
289
- showTrace: process.env.NODE_ENV !== "production"
295
+ showTrace: process.env.NODE_ENV !== "production",
290
296
  });
291
297
  ```
292
298
 
@@ -303,7 +309,7 @@ const handler = await httpHandler(error, {
303
309
  // Or send to external logging service
304
310
  // logToService({ error: error.message, url: request.url, method: request.method });
305
311
  },
306
- showTrace: process.env.NODE_ENV !== "production"
312
+ showTrace: process.env.NODE_ENV !== "production",
307
313
  });
308
314
  ```
309
315
 
@@ -373,8 +379,8 @@ If you would like to help take a look at the [list of issues](https://github.com
373
379
 
374
380
  ## Credits
375
381
 
376
- - [Daniel Bannert](https://github.com/prisis)
377
- - [All Contributors](https://github.com/visulima/visulima/graphs/contributors)
382
+ - [Daniel Bannert](https://github.com/prisis)
383
+ - [All Contributors](https://github.com/visulima/visulima/graphs/contributors)
378
384
 
379
385
  ## License
380
386
 
@@ -1,15 +1,15 @@
1
1
  import { IncomingMessage, ServerResponse } from 'node:http';
2
- import { a as ErrorHandler } from '../packem_shared/types.d-DLy8CCca.js';
2
+ import { a as ErrorHandler } from '../packem_shared/types.d-BQZBUb3b.js';
3
3
 
4
4
  type HtmlErrorHandlerOptions = {
5
- errorPage?: string | ((params: {
5
+ cspNonce?: string;
6
+ errorPage?: string | ((parameters: {
6
7
  error: Error;
8
+ reasonPhrase: string;
7
9
  request: IncomingMessage;
8
10
  response: ServerResponse;
9
- reasonPhrase: string;
10
11
  statusCode: number;
11
12
  }) => string | Promise<string>);
12
- cspNonce?: string;
13
13
  };
14
14
  declare const htmlErrorHandler: (options?: HtmlErrorHandlerOptions) => ErrorHandler;
15
15
 
@@ -1,4 +1,4 @@
1
- var l=Object.defineProperty;var d=(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-DOfo6_g6.js";var g=Object.defineProperty,s=d((e,r)=>g(e,"name",{value:r,configurable:!0}),"n");const x=s((e={})=>async(r,n,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,request:n,response:t,reasonPhrase:o,statusCode:t.statusCode}):e.errorPage;if(i){t.end(i);return}}t.end(`<!DOCTYPE html>
1
+ var l=Object.defineProperty;var d=(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=d((e,r)=>g(e,"name",{value:r,configurable:!0}),"n");const x=s((e={})=>async(r,n,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:n,response:t,statusCode:t.statusCode}):e.errorPage;if(i){t.end(i);return}}t.end(`<!DOCTYPE html>
2
2
  <html lang="en">
3
3
  <head>
4
4
  <meta charset="utf-8">
@@ -1,12 +1,12 @@
1
1
  import { IncomingMessage, ServerResponse } from 'node:http';
2
- import { a as ErrorHandler } from '../packem_shared/types.d-DLy8CCca.js';
2
+ import { a as ErrorHandler } from '../packem_shared/types.d-BQZBUb3b.js';
3
3
 
4
4
  type JsonErrorBody = Record<string, unknown> | unknown[];
5
- type JsonErrorFormatter = (params: {
5
+ type JsonErrorFormatter = (parameters: {
6
6
  error: Error;
7
+ reasonPhrase: string;
7
8
  request: IncomingMessage;
8
9
  response: ServerResponse;
9
- reasonPhrase: string;
10
10
  statusCode: number;
11
11
  }) => JsonErrorBody | Promise<JsonErrorBody>;
12
12
  type JsonErrorHandlerOptions = {
@@ -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-DOfo6_g6.js";import{s as n}from"../packem_shared/send-json-Cedv8-Bt.js";import{s as i}from"../packem_shared/set-error-headers-BWc7Sbh2.js";var g=Object.defineProperty,l=a((e,r)=>g(e,"name",{value:r,configurable:!0}),"n");const P=l((e={})=>async(r,d,s)=>{f(s,r),i(s,r);const o=s.statusCode,t=u(o)||"An error occurred";if(e.formatter){const c=await e.formatter({error:r,request:d,response:s,reasonPhrase:t,statusCode:o});n(s,c);return}const m=r.expose;n(s,{statusCode:o,error:t,message:r.message||t,...m?{stack:r.stack}:{}})},"jsonErrorHandler");export{P as jsonErrorHandler};
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,4 +1,4 @@
1
- import { a as ErrorHandler } from '../packem_shared/types.d-DLy8CCca.js';
1
+ import { a as ErrorHandler } from '../packem_shared/types.d-BQZBUb3b.js';
2
2
  import 'node:http';
3
3
 
4
4
  declare const jsonapiErrorHandler: ErrorHandler;
@@ -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-DOfo6_g6.js";import{s as t}from"../packem_shared/send-json-Cedv8-Bt.js";import{s as c}from"../packem_shared/set-error-headers-BWc7Sbh2.js";var g=Object.defineProperty,C=i((e,s)=>g(e,"name",{value:s,configurable:!0}),"n");const d="An error occurred",z=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{z as default};
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,12 +1,12 @@
1
1
  import { IncomingMessage, ServerResponse } from 'node:http';
2
- import { a as ErrorHandler } from '../packem_shared/types.d-DLy8CCca.js';
2
+ import { a as ErrorHandler } from '../packem_shared/types.d-BQZBUb3b.js';
3
3
 
4
4
  type JsonpErrorBody = Record<string, unknown> | unknown[];
5
- type JsonpErrorFormatter = (params: {
5
+ type JsonpErrorFormatter = (parameters: {
6
6
  error: Error;
7
+ reasonPhrase: string;
7
8
  request: IncomingMessage;
8
9
  response: ServerResponse;
9
- reasonPhrase: string;
10
10
  statusCode: number;
11
11
  }) => JsonpErrorBody | Promise<JsonpErrorBody>;
12
12
  type JsonpErrorHandlerOptions = {
@@ -1 +1 @@
1
- var i=Object.defineProperty;var n=(a,e)=>i(a,"name",{value:e,configurable:!0});import{getReasonPhrase as u}from"http-status-codes";import{a as f}from"../packem_shared/add-status-code-to-response-DOfo6_g6.js";import{s as h}from"../packem_shared/set-error-headers-BWc7Sbh2.js";var g=Object.defineProperty,b=n((a,e)=>g(a,"name",{value:e,configurable:!0}),"c");const k="callback",C=b((a={})=>async(e,c,r)=>{f(r,e),h(r,e);const t=r.statusCode,s=u(t)||"An error occurred",l=new URL(c.url??"http://localhost","http://localhost"),p=a.callbackParamName||k,m=l.searchParams.get(p)||"callback";let o;if(a.formatter)o=await a.formatter({error:e,request:c,response:r,reasonPhrase:s,statusCode:t});else{const d=e.expose;o={statusCode:t,error:s,message:e.message||s,...d?{stack:e.stack}:{}}}r.setHeader("content-type","application/javascript; charset=utf-8"),r.end(`${m}(${JSON.stringify(o)});`)},"jsonpErrorHandler");export{C as jsonpErrorHandler};
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,4 +1,4 @@
1
- import { a as ErrorHandler } from '../packem_shared/types.d-DLy8CCca.js';
1
+ import { a as ErrorHandler } from '../packem_shared/types.d-BQZBUb3b.js';
2
2
  import 'node:http';
3
3
 
4
4
  declare const problemErrorHandler: ErrorHandler;
@@ -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-DOfo6_g6.js";import{s as n}from"../packem_shared/send-json-Cedv8-Bt.js";import{s as C}from"../packem_shared/set-error-headers-BWc7Sbh2.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:r,stack:a}=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:r,...l?{trace:a}:{}},"application/problem+json")}else b(t,e),n(t,{type:d,title:p(t.statusCode)||u,status:t.statusCode,detail:r,...e.expose?{trace:a}:{}},"application/problem+json")},"problemErrorHandler");export{R as default};
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,11 +1,11 @@
1
1
  import { IncomingMessage, ServerResponse } from 'node:http';
2
- import { a as ErrorHandler } from '../packem_shared/types.d-DLy8CCca.js';
2
+ import { a as ErrorHandler } from '../packem_shared/types.d-BQZBUb3b.js';
3
3
 
4
- type TextErrorFormatter = (params: {
4
+ type TextErrorFormatter = (parameters: {
5
5
  error: Error;
6
+ reasonPhrase: string;
6
7
  request: IncomingMessage;
7
8
  response: ServerResponse;
8
- reasonPhrase: string;
9
9
  statusCode: number;
10
10
  }) => string | Promise<string>;
11
11
  type TextErrorHandlerOptions = {
@@ -1,3 +1,3 @@
1
- var i=Object.defineProperty;var d=(t,e)=>i(t,"name",{value:e,configurable:!0});import{getReasonPhrase as p}from"http-status-codes";import{a as f}from"../packem_shared/add-status-code-to-response-DOfo6_g6.js";import{s as u}from"../packem_shared/set-error-headers-BWc7Sbh2.js";var l=Object.defineProperty,x=d((t,e)=>l(t,"name",{value:e,configurable:!0}),"m");const h=x((t={})=>async(e,m,r)=>{f(r,e),u(r,e);const o=r.statusCode,s=p(o)||"Error";if(r.setHeader("content-type","text/plain; charset=utf-8"),t.formatter){const c=await t.formatter({error:e,request:m,response:r,reasonPhrase:s,statusCode:o});r.end(c);return}const a=e.message||s,n=e.expose?e.stack:void 0;r.end(n?`${a}
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}
2
2
 
3
- ${n}`:a)},"textErrorHandler");export{h as textErrorHandler};
3
+ ${n}`:s)},"textErrorHandler");export{E as textErrorHandler};
@@ -1,28 +1,28 @@
1
1
  import { IncomingMessage, ServerResponse } from 'node:http';
2
- import { a as ErrorHandler } from '../packem_shared/types.d-DLy8CCca.js';
2
+ import { a as ErrorHandler } from '../packem_shared/types.d-BQZBUb3b.js';
3
3
 
4
4
  type XmlErrorBody = Record<string, unknown> | unknown[];
5
- type XmlErrorFormatter = (params: {
5
+ type XmlErrorFormatter = (parameters: {
6
6
  error: Error;
7
+ reasonPhrase: string;
7
8
  request: IncomingMessage;
8
9
  response: ServerResponse;
9
- reasonPhrase: string;
10
10
  statusCode: number;
11
11
  }) => XmlErrorBody | Promise<XmlErrorBody>;
12
12
  type ToXmlOptions = {
13
- indent?: string;
14
- header?: string | boolean;
15
- attributeReplacements?: Record<string, string>;
16
- attributeFilter?: (key: string, value: unknown) => boolean;
17
13
  attributeExplicitTrue?: boolean;
14
+ attributeFilter?: (key: string, value: unknown) => boolean;
15
+ attributeReplacements?: Record<string, string>;
18
16
  contentMap?: (content: string) => string;
19
17
  contentReplacements?: Record<string, string>;
18
+ header?: string | boolean;
19
+ indent?: string;
20
20
  selfCloseTags?: boolean;
21
21
  };
22
22
  type XmlErrorHandlerOptions = {
23
23
  formatter?: XmlErrorFormatter;
24
- xmlHeader?: boolean;
25
24
  toXml?: ToXmlOptions;
25
+ xmlHeader?: boolean;
26
26
  };
27
27
  declare const xmlErrorHandler: (options?: XmlErrorHandlerOptions) => ErrorHandler;
28
28
 
@@ -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-DOfo6_g6.js";import{s as X}from"../packem_shared/set-error-headers-BWc7Sbh2.js";var f=Object.defineProperty,b=l((t,e)=>f(t,"name",{value:e,configurable:!0}),"l");const E=b((t={})=>async(e,n,o)=>{d(o,e),X(o,e);const r=o.statusCode,a=p(r)||"An error occurred";let s;if(t.formatter)s=await t.formatter({error:e,request:n,response:o,reasonPhrase:a,statusCode:r});else{const i=e.expose;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{E as xmlErrorHandler};
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};
@@ -23,8 +23,8 @@ type BaseCliOptions = {
23
23
  type CliHandlerOptions = BaseCliOptions & {
24
24
  logger?: CliLogger;
25
25
  };
26
+ declare const terminalOutput: (error: Error, options?: CliHandlerOptions) => Promise<void>;
26
27
 
27
28
  declare const ansiHandler: (error: Error, options?: BaseCliOptions) => Promise<string>;
28
- declare const cliHandler: (error: Error, options?: CliHandlerOptions) => Promise<void>;
29
29
 
30
- export { type BaseCliOptions, type CliHandlerOptions, ansiHandler, cliHandler };
30
+ export { type BaseCliOptions, type CliHandlerOptions, ansiHandler, terminalOutput as cliHandler };
@@ -1,3 +1,3 @@
1
- var g=Object.defineProperty;var c=(e,r)=>g(e,"name",{value:r,configurable:!0});import{parseStacktrace as b}from"@visulima/error/stacktrace";import{boxen as x}from"@visulima/boxen";import{renderError as j}from"@visulima/error/error";import{readFile as v}from"node:fs/promises";import{fileURLToPath as y}from"node:url";import{ruleBasedFinder as h,errorHintFinder as w}from"@visulima/error/solution";var O=Object.defineProperty,$=c((e,r)=>O(e,"name",{value:r,configurable:!0}),"r");const A=["cjs","mjs"],F=["mdoc"],B=$(e=>{const r=(e.split("?")[0]??e).split(".").pop()?.toLowerCase();if(!r||A.includes(r))return"javascript";if(F.includes(r))return"markdown";switch(r){case"js":return"javascript";case"json":return"json";case"json5":return"json5";case"jsonc":return"jsonc";case"jsx":return"jsx";case"sql":return"sql";case"ts":return"typescript";case"tsx":return"tsx";case"xml":return"xml";case"md":return"markdown";case"mdx":return"mdx";default:return"javascript"}},"findLanguageBasedOnExtension");var P=Object.defineProperty,k=c((e,r)=>P(e,"name",{value:r,configurable:!0}),"o$1");const u=new Map,H=k(async e=>{if(/^(?:http|https|file|data):/.test(e)){if(u.has(e))return u.get(e);if(e.startsWith("file:"))try{const r=y(e),t=await v(r,"utf8");return u.set(e,t),t}catch(r){console.log(r);return}try{const r=await fetch(e);if(!r.ok)return;const t=await r.text();return u.set(e,t),t}catch(r){console.log(r);return}}},"getFileSource");var L=Object.defineProperty,f=c((e,r)=>L(e,"name",{value:r,configurable:!0}),"d");const S=f(e=>e.replace(/^\s*#+\s*/,"").trim(),"sanitizeTitle"),T=f(async(e,r,t=!1)=>{const o=[...r,h,w],n=b(e,{frameLimit:1})[0]??{};for await(const i of o.sort((a,s)=>a.priority-s.priority)){const{handle:a,name:s}=i;if(t&&console.debug(`Running solution finder: ${s}`),typeof a!="function")continue;const l=await a(e,{file:n.file??"",language:B(n.file??""),line:n.line??0,snippet:n.file?await H(n.file):""});if(l)return l}},"runSolutionFinders"),d=f(async(e,r)=>{const{solutionFinders:t=[],solutionTitle:o,color:n,debug:i=!1,...a}=r,s=j(e,{...a,...n?.codeFrame}),l=await T(e,t,i);if(!l)return{errorAnsi:s,solutionBox:void 0};const p=S(l.header??o??"A possible solution to this error"),m=x(l.body,{borderStyle:"round",padding:{top:1,right:2,bottom:1,left:2},margin:{top:0,right:0,bottom:0,left:0},headerText:`💡 ${p}`,headerAlignment:"left",textAlignment:"left",...n?.boxen});return{errorAnsi:s,solutionBox:m}},"buildOutput"),q=f(async(e,r={})=>{const{logger:t=console,...o}=r,{errorAnsi:n,solutionBox:i}=await d(e,o);t.error(n),i&&(t.log(""),t.log(i))},"terminalOutput");var C=Object.defineProperty,E=c((e,r)=>C(e,"name",{value:r,configurable:!0}),"o");const I=E(async(e,r={})=>{const{errorAnsi:t,solutionBox:o}=await d(e,r);return o===void 0?t:`${t}
1
+ var o=Object.defineProperty;var a=(r,e)=>o(r,"name",{value:e,configurable:!0});import{buildOutput as i}from"../packem_shared/cliHandler-CFffArNH.js";import{terminalOutput as f}from"../packem_shared/cliHandler-CFffArNH.js";var u=Object.defineProperty,l=a((r,e)=>u(r,"name",{value:e,configurable:!0}),"o");const d=l(async(r,e={})=>{const{errorAnsi:t,solutionBox:n}=await i(r,e);return n===void 0?t:`${t}
2
2
 
3
- ${o}`},"ansiHandler"),J=q;export{I as ansiHandler,J as cliHandler};
3
+ ${n}`},"ansiHandler");export{d as ansiHandler,f as cliHandler};
@@ -1,11 +1,11 @@
1
1
  import { HtmlErrorHandlerOptions } from '../../error-handler/html-error-handler.js';
2
- import { F as FetchErrorHandlers } from '../../packem_shared/types.d-DLy8CCca.js';
2
+ import { F as FetchErrorHandlers } from '../../packem_shared/types.d-BQZBUb3b.js';
3
3
  import 'node:http';
4
4
 
5
5
  declare const fetchHandler: (error: Error, options?: HtmlErrorHandlerOptions & {
6
- showTrace?: boolean;
7
6
  extraHandlers?: FetchErrorHandlers;
8
7
  onError?: (error: Error, request: Request) => void | Promise<void>;
8
+ showTrace?: boolean;
9
9
  }) => Promise<(request: Request) => Promise<Response>>;
10
10
 
11
11
  export { fetchHandler as default };
@@ -1 +1 @@
1
- var b=Object.defineProperty;var h=(s,e)=>b(s,"name",{value:e,configurable:!0});import{htmlErrorHandler as g}from"../../error-handler/html-error-handler.js";import y from"../../error-handler/jsonapi-error-handler.js";import u from"../../error-handler/problem-error-handler.js";import{textErrorHandler as w}from"../../error-handler/text-error-handler.js";import{jsonErrorHandler as H}from"../../error-handler/json-error-handler.js";import{jsonpErrorHandler as v}from"../../error-handler/jsonp-error-handler.js";import{xmlErrorHandler as L}from"../../error-handler/xml-error-handler.js";var j=Object.defineProperty,t=h((s,e)=>j(s,"name",{value:e,configurable:!0}),"e");class x{static{h(this,"u")}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="";setHeader(e,a){return this.headers[e.toLowerCase()]=a,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,a,n){return this.statusCode=e,typeof a=="string"&&(this.statusMessage=a),typeof a=="object"&&(n=a),n&&Object.assign(this.headers,n),this}write(e){return this.body+=e.toString(),!0}end(e,a,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(()=>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");sendDate=!0;strictContentLength=!1;chunkedEncoding=!1;shouldKeepAlive=!0;useChunkedEncodingByDefault=!0;_hasBody=!0;_trailer="";connection=null;socket=null}const C=t((s={})=>{const e=g(s);return async(a,n)=>{const o={url:n.url,method:n.method,headers:Object.fromEntries(Array.from(n.headers.entries()))},d=new x;await e(a,o,d);const r=d.getHeader("content-type")||"text/html; charset=utf-8";return new Response(d.body,{status:d.statusCode,headers:{"content-type":r,...d.headers}})}},"fetchHtmlErrorHandler");var E=Object.defineProperty,c=h((s,e)=>E(s,"name",{value:e,configurable:!0}),"l");const k=c(s=>{if(!s)return"text/html";const e=s.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"),l=c(s=>async(e,a)=>{const n={url:a.url,method:a.method,headers:Object.fromEntries(a.headers.entries())},o={statusCode:200,headers:{},_body:"",setHeader(r,i){this.headers[r.toLowerCase()]=i},getHeader(r){return this.headers[r.toLowerCase()]},getHeaders(){return{...this.headers}},writeHead(r){this.statusCode=r},write(r){this._body+=r.toString()},end(r){r&&(this._body+=r.toString())},flushHeaders(){}};await s(e,n,o);const d={};for(const[r,i]of Object.entries(o.headers))Array.isArray(i)?d[r]=i.join(", "):d[r]=String(i);return new Response(o._body,{status:o.statusCode,headers:d})},"adaptErrorHandlerToFetch"),S=c((s,e,a)=>async(n,o)=>{const d=o.headers.get("accept"),r=k(d);let i=a||l(u);r==="text/html"&&a?i=a:r==="application/vnd.api+json"?i=l(y):r==="application/problem+json"?i=l(u):r==="application/json"?i=l(H()):r==="text/plain"?i=l(w()):r==="application/javascript"?i=l(v()):r==="application/xml"&&(i=l(L()));for(const{handler:p,regex:m}of s){const f=d??"";if(m.test(f)){i=p;break}}return n.expose=e,i(n,o)},"createFetchNegotiatedErrorHandler");var O=Object.defineProperty,M=h((s,e)=>O(s,"name",{value:e,configurable:!0}),"t");const B=M(async(s,e={})=>{const a=C(e),n=S(e.extraHandlers??[],e.showTrace??!0,a);return async o=>(e?.onError&&await e.onError(s,o),n(s,o))},"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 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,11 +1,11 @@
1
1
  import { IncomingMessage, ServerResponse } from 'node:http';
2
2
  import { HtmlErrorHandlerOptions } from '../../error-handler/html-error-handler.js';
3
- import { E as ErrorHandlers } from '../../packem_shared/types.d-DLy8CCca.js';
3
+ import { E as ErrorHandlers } from '../../packem_shared/types.d-BQZBUb3b.js';
4
4
 
5
- declare const httpHandler: (error: Error, options?: HtmlErrorHandlerOptions & {
6
- showTrace?: boolean;
5
+ declare const nodeHandler: (error: Error, options?: HtmlErrorHandlerOptions & {
7
6
  extraHandlers?: ErrorHandlers;
8
7
  onError?: (error: Error, request: IncomingMessage, response: ServerResponse) => void | Promise<void>;
8
+ showTrace?: boolean;
9
9
  }) => Promise<(request: IncomingMessage, response: ServerResponse) => Promise<void>>;
10
10
 
11
- export { httpHandler as default };
11
+ export { nodeHandler as default };
@@ -1 +1 @@
1
- var s=Object.defineProperty;var o=(a,r)=>s(a,"name",{value:r,configurable:!0});import{htmlErrorHandler as c}from"../../error-handler/html-error-handler.js";import m from"../../packem_shared/createNegotiatedErrorHandler-ElYcOlsu.js";var i=Object.defineProperty,u=o((a,r)=>i(a,"name",{value:r,configurable:!0}),"s");const h=u(async(a,r={})=>{const n=c(r),l=m(r.extraHandlers??[],r.showTrace??!0,n);return async(t,e)=>{r?.onError&&await r.onError(a,t,e),await l(a,t,e)}},"httpHandler");export{h as default};
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};
package/dist/index.d.ts CHANGED
@@ -1,12 +1,12 @@
1
- export { default as jsonapiErrorHandler } from './error-handler/jsonapi-error-handler.js';
2
- export { default as problemErrorHandler } from './error-handler/problem-error-handler.js';
3
- export { HtmlErrorHandlerOptions, htmlErrorHandler } from './error-handler/html-error-handler.js';
4
1
  import { IncomingMessage, ServerResponse } from 'node:http';
5
- import { E as ErrorHandlers, a as ErrorHandler } from './packem_shared/types.d-DLy8CCca.js';
6
- export { A as ApiFormat } from './packem_shared/types.d-DLy8CCca.js';
7
- export { TextErrorFormatter, TextErrorHandlerOptions, textErrorHandler } from './error-handler/text-error-handler.js';
2
+ import { E as ErrorHandlers, a as ErrorHandler } from './packem_shared/types.d-BQZBUb3b.js';
3
+ export { A as ApiFormat } from './packem_shared/types.d-BQZBUb3b.js';
4
+ export { HtmlErrorHandlerOptions, htmlErrorHandler } from './error-handler/html-error-handler.js';
8
5
  export { JsonErrorBody, JsonErrorFormatter, JsonErrorHandlerOptions, jsonErrorHandler } from './error-handler/json-error-handler.js';
6
+ export { default as jsonapiErrorHandler } from './error-handler/jsonapi-error-handler.js';
9
7
  export { JsonpErrorBody, JsonpErrorFormatter, JsonpErrorHandlerOptions, jsonpErrorHandler } from './error-handler/jsonp-error-handler.js';
8
+ export { default as problemErrorHandler } from './error-handler/problem-error-handler.js';
9
+ export { TextErrorFormatter, TextErrorHandlerOptions, textErrorHandler } from './error-handler/text-error-handler.js';
10
10
  export { ToXmlOptions, XmlErrorBody, XmlErrorFormatter, XmlErrorHandlerOptions, xmlErrorHandler } from './error-handler/xml-error-handler.js';
11
11
 
12
12
  declare const createNegotiatedErrorHandler: <Request extends IncomingMessage, Response extends ServerResponse>(errorHandlers: ErrorHandlers, showTrace: boolean, defaultHtmlHandler?: ErrorHandler) => (error: Error, request: Request, response: Response) => Promise<void>;
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{default as e}from"./error-handler/jsonapi-error-handler.js";import{default as t}from"./error-handler/problem-error-handler.js";import{htmlErrorHandler as d}from"./error-handler/html-error-handler.js";import{default as m}from"./packem_shared/createNegotiatedErrorHandler-ElYcOlsu.js";import{textErrorHandler as p}from"./error-handler/text-error-handler.js";import{jsonErrorHandler as E}from"./error-handler/json-error-handler.js";import{jsonpErrorHandler as s}from"./error-handler/jsonp-error-handler.js";import{xmlErrorHandler as u}from"./error-handler/xml-error-handler.js";export{m as createNegotiatedErrorHandler,d as htmlErrorHandler,E as jsonErrorHandler,e as jsonapiErrorHandler,s as jsonpErrorHandler,t as problemErrorHandler,p as textErrorHandler,u as xmlErrorHandler};
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};
@@ -0,0 +1 @@
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};
@@ -0,0 +1 @@
1
+ var d=Object.defineProperty;var u=(e,r)=>d(e,"name",{value:r,configurable:!0});import{parseStacktrace as g}from"@visulima/error/stacktrace";import{boxen as y}from"@visulima/boxen";import{renderError as h}from"@visulima/error/error";import{readFile as x}from"node:fs/promises";import{fileURLToPath as j}from"node:url";import{ruleBasedFinder as v,errorHintFinder as b}from"@visulima/error/solution";var w=Object.defineProperty,O=u((e,r)=>w(e,"name",{value:r,configurable:!0}),"t");const F=["cjs","mjs"],A=["mdoc"],B=O(e=>{const r=(e.split("?")[0]??e).split(".").pop()?.toLowerCase();if(!r||F.includes(r))return"javascript";if(A.includes(r))return"markdown";switch(r){case"js":return"javascript";case"json":return"json";case"json5":return"json5";case"jsonc":return"jsonc";case"jsx":return"jsx";case"sql":return"sql";case"ts":return"typescript";case"tsx":return"tsx";case"xml":return"xml";case"md":return"markdown";case"mdx":return"mdx";case"svelte":return"svelte";case"vue":return"vue";case"html":return"html";case"css":return"css";case"scss":return"scss";case"less":return"less";case"sass":return"sass";case"stylus":return"stylus";case"styl":return"styl";default:return"javascript"}},"findLanguageBasedOnExtension");var k=Object.defineProperty,L=u((e,r)=>k(e,"name",{value:r,configurable:!0}),"s");const c=new Map,P=L(async e=>{if(/^(?:http|https|file|data):/.test(e)){if(c.has(e))return c.get(e);if(e.startsWith("file:"))try{const r=j(e),t=await x(r,"utf8");return c.set(e,t),t}catch{return}try{const r=await fetch(e);if(!r.ok)return;const t=await r.text();return c.set(e,t),t}catch{return}}},"getFileSource");var S=Object.defineProperty,l=u((e,r)=>S(e,"name",{value:r,configurable:!0}),"d");const T=l(e=>e.replace(/^\s*#+\s*/,"").trim(),"sanitizeTitle"),$=l(async(e,r,t=!1)=>{const i=[...r,v,b],s=g(e,{frameLimit:1})[0]??{};for await(const o of i.sort((a,n)=>a.priority-n.priority)){const{handle:a}=o;if(typeof a!="function")continue;const n=await a(e,{file:s.file??"",language:B(s.file??""),line:s.line??0,snippet:s.file?await P(s.file):""});if(n)return n}},"runSolutionFinders"),q=l(async(e,r)=>{const{solutionFinders:t=[],solutionTitle:i,color:s,debug:o=!1,...a}=r,n=h(e,{...a,...s?.codeFrame}),f=await $(e,t,o);if(!f)return{errorAnsi:n,solutionBox:void 0};const m=T(f.header??i??"A possible solution to this error"),p=y(f.body,{borderStyle:"round",padding:{top:1,right:2,bottom:1,left:2},margin:{top:0,right:0,bottom:0,left:0},headerText:`💡 ${m}`,headerAlignment:"left",textAlignment:"left",...s?.boxen});return{errorAnsi:n,solutionBox:p}},"buildOutput"),W=l(async(e,r={})=>{const{logger:t=console,...i}=r,{errorAnsi:s,solutionBox:o}=await q(e,i);t.error(s),o&&(t.log(""),t.log(o))},"terminalOutput");export{q as buildOutput,W as terminalOutput};
@@ -0,0 +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};
@@ -0,0 +1 @@
1
+ var c=Object.defineProperty;var o=(e,r)=>c(e,"name",{value:r,configurable:!0});var n=Object.defineProperty,s=o((e,r)=>n(e,"name",{value:r,configurable:!0}),"o");const b=s((e,r)=>{const a=r.headers??{};Object.keys(a).forEach(t=>{e.setHeader(t,a[t])})},"setErrorHeaders");export{b as a};
@@ -6,10 +6,7 @@ type ErrorHandler = <Request extends IncomingMessage, Response extends ServerRes
6
6
  response: Response,
7
7
  ) => Promise<void> | void;
8
8
 
9
- type FetchErrorHandler = (
10
- error: unknown,
11
- request: Request,
12
- ) => Promise<Response> | Response;
9
+ type FetchErrorHandler = (error: unknown, request: Request) => Promise<Response>;
13
10
 
14
11
  type ErrorHandlers = {
15
12
  handler: ErrorHandler;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visulima/error-handler",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Error handlers for use in development and production environments.",
5
5
  "keywords": [
6
6
  "visulima",
@@ -135,7 +135,7 @@
135
135
  "dependencies": {
136
136
  "@tinyhttp/accepts": "^2.2.4",
137
137
  "@visulima/boxen": "2.0.3",
138
- "@visulima/error": "4.6.1",
138
+ "@visulima/error": "4.6.2",
139
139
  "http-errors": "^2.0.0",
140
140
  "http-status-codes": "^2.3.0",
141
141
  "jstoxml": "^7.0.1",
@@ -1 +0,0 @@
1
- var r=Object.defineProperty;var a=(e,s)=>r(e,"name",{value:s,configurable:!0});import{StatusCodes as u}from"http-status-codes";var d=Object.defineProperty,n=a((e,s)=>d(e,"name",{value:s,configurable:!0}),"s");const i=n((e,s)=>{const o=s,t=Number(o.statusCode??o.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 j=Object.defineProperty;var l=(a,o)=>j(a,"name",{value:o,configurable:!0});import d from"../error-handler/jsonapi-error-handler.js";import c from"../error-handler/problem-error-handler.js";import{textErrorHandler as v}from"../error-handler/text-error-handler.js";import{jsonErrorHandler as b}from"../error-handler/json-error-handler.js";import{jsonpErrorHandler as y}from"../error-handler/jsonp-error-handler.js";import{xmlErrorHandler as E}from"../error-handler/xml-error-handler.js";import{Accepts as H}from"@tinyhttp/accepts";var g=Object.defineProperty,h=l((a,o)=>g(a,"name",{value:o,configurable:!0}),"i");const q=h((a,o,e)=>async(n,i,m)=>{const r=new H(i).type(["text/html","application/vnd.api+json","application/problem+json","application/json","text/plain","application/javascript","text/javascript","application/xml","text/xml"]);let t=e||c;r==="text/html"&&e?t=e:r==="application/vnd.api+json"?t=d:r==="application/problem+json"?t=c:r==="application/json"?t=b():r==="text/plain"?t=v():r==="application/javascript"||r==="text/javascript"?t=y():(r==="application/xml"||r==="text/xml")&&(t=E());for(const{handler:s,regex:x}of a){const p=i.headers.accept??"",f=Array.isArray(p)?p.join(","):p;if(x.test(f)){t=s;break}}n.expose=o,await t(n,i,m)},"createNegotiatedErrorHandler");export{q as default};
@@ -1 +0,0 @@
1
- var o=Object.defineProperty;var s=(e,r)=>o(e,"name",{value:r,configurable:!0});var c=Object.defineProperty,n=s((e,r)=>c(e,"name",{value:r,configurable:!0}),"o");const b=n((e,r)=>{const a=r.headers??{};Object.keys(a).forEach(t=>{e.setHeader(t,a[t])})},"setErrorHeaders");export{b as s};