@visulima/error-handler 1.0.10 → 1.0.12
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 +32 -0
- package/dist/error-handler/create-negotiated-error-handler.d.ts +4 -0
- package/dist/error-handler/fetch-create-negotiated-error-handler.d.ts +3 -0
- package/dist/error-handler/fetch-html-error-handler.d.ts +3 -0
- package/dist/error-handler/html-error-handler.d.ts +4 -8
- package/dist/error-handler/json-error-handler.d.ts +6 -10
- package/dist/error-handler/jsonapi-error-handler.d.ts +2 -5
- package/dist/error-handler/jsonp-error-handler.d.ts +6 -10
- package/dist/error-handler/problem-error-handler.d.ts +6 -5
- package/dist/error-handler/text-error-handler.d.ts +5 -9
- package/dist/error-handler/utils/add-status-code-to-response.d.ts +2 -0
- package/dist/error-handler/utils/send-json.d.ts +8 -0
- package/dist/error-handler/utils/set-error-headers.d.ts +3 -0
- package/dist/error-handler/xml-error-handler.d.ts +7 -11
- package/dist/handler/cli-handler.d.ts +4 -31
- package/dist/handler/cli-handler.js +1 -1
- package/dist/handler/http/fetch-handler.d.ts +3 -6
- package/dist/handler/http/node-handler.d.ts +4 -6
- package/dist/index.d.ts +14 -14
- package/dist/packem_shared/cliHandler-nqs3YWf5.js +1 -0
- package/package.json +3 -3
- package/dist/packem_shared/cliHandler-CB1c5j_A.js +0 -1
- package/dist/packem_shared/types.d-BQZBUb3b.d.ts +0 -23
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,35 @@
|
|
|
1
|
+
## @visulima/error-handler [1.0.12](https://github.com/visulima/visulima/compare/@visulima/error-handler@1.0.11...@visulima/error-handler@1.0.12) (2025-11-12)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
* update package configurations and TypeScript definitions ([b59aa59](https://github.com/visulima/visulima/commit/b59aa59dac1508216b944f4b917fb4a7ab1f70a4))
|
|
6
|
+
|
|
7
|
+
### Miscellaneous Chores
|
|
8
|
+
|
|
9
|
+
* Add jsr file to all packages for release ([#565](https://github.com/visulima/visulima/issues/565)) ([ec91652](https://github.com/visulima/visulima/commit/ec91652b4e4112adf14ba152c1239a7703ba425a))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Dependencies
|
|
13
|
+
|
|
14
|
+
* **@visulima/boxen:** upgraded to 2.0.9
|
|
15
|
+
* **@visulima/error:** upgraded to 5.0.5
|
|
16
|
+
|
|
17
|
+
## @visulima/error-handler [1.0.11](https://github.com/visulima/visulima/compare/@visulima/error-handler@1.0.10...@visulima/error-handler@1.0.11) (2025-11-07)
|
|
18
|
+
|
|
19
|
+
### Bug Fixes
|
|
20
|
+
|
|
21
|
+
* update TypeScript configurations and improve linting across multiple packages ([6f25ec7](https://github.com/visulima/visulima/commit/6f25ec7841da7246f8f9166efc5292a7089d37ee))
|
|
22
|
+
|
|
23
|
+
### Miscellaneous Chores
|
|
24
|
+
|
|
25
|
+
* update npm and pnpm configurations for monorepo optimization ([#564](https://github.com/visulima/visulima/issues/564)) ([5512b42](https://github.com/visulima/visulima/commit/5512b42f672c216b6a3c9e39035199a4ebd9a4b8))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Dependencies
|
|
29
|
+
|
|
30
|
+
* **@visulima/boxen:** upgraded to 2.0.8
|
|
31
|
+
* **@visulima/error:** upgraded to 5.0.4
|
|
32
|
+
|
|
1
33
|
## @visulima/error-handler [1.0.10](https://github.com/visulima/visulima/compare/@visulima/error-handler@1.0.9...@visulima/error-handler@1.0.10) (2025-11-05)
|
|
2
34
|
|
|
3
35
|
### Bug Fixes
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
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>;
|
|
4
|
+
export default createNegotiatedErrorHandler;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { FetchErrorHandlers } from "./types.d.d.ts";
|
|
2
|
+
declare const createFetchNegotiatedErrorHandler: (errorHandlers: FetchErrorHandlers, showTrace: boolean, defaultHtmlHandler?: (error: Error, request: Request) => Promise<Response>) => (error: Error, request: Request) => Promise<Response>;
|
|
3
|
+
export default createFetchNegotiatedErrorHandler;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { IncomingMessage, ServerResponse } from
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
type HtmlErrorHandlerOptions = {
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
+
import type { ErrorHandler } from "./types.d.d.ts";
|
|
3
|
+
export type HtmlErrorHandlerOptions = {
|
|
5
4
|
cspNonce?: string;
|
|
6
5
|
errorPage?: string | ((parameters: {
|
|
7
6
|
error: Error;
|
|
@@ -11,7 +10,4 @@ type HtmlErrorHandlerOptions = {
|
|
|
11
10
|
statusCode: number;
|
|
12
11
|
}) => string | Promise<string>);
|
|
13
12
|
};
|
|
14
|
-
declare const htmlErrorHandler: (options?: HtmlErrorHandlerOptions) => ErrorHandler;
|
|
15
|
-
|
|
16
|
-
export { htmlErrorHandler };
|
|
17
|
-
export type { HtmlErrorHandlerOptions };
|
|
13
|
+
export declare const htmlErrorHandler: (options?: HtmlErrorHandlerOptions) => ErrorHandler;
|
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
import { IncomingMessage, ServerResponse } from
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
type
|
|
5
|
-
type JsonErrorFormatter = (parameters: {
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
+
import type { ErrorHandler } from "./types.d.d.ts";
|
|
3
|
+
export type JsonErrorBody = Record<string, unknown> | unknown[];
|
|
4
|
+
export type JsonErrorFormatter = (parameters: {
|
|
6
5
|
error: Error;
|
|
7
6
|
reasonPhrase: string;
|
|
8
7
|
request: IncomingMessage;
|
|
9
8
|
response: ServerResponse;
|
|
10
9
|
statusCode: number;
|
|
11
10
|
}) => JsonErrorBody | Promise<JsonErrorBody>;
|
|
12
|
-
type JsonErrorHandlerOptions = {
|
|
11
|
+
export type JsonErrorHandlerOptions = {
|
|
13
12
|
formatter?: JsonErrorFormatter;
|
|
14
13
|
};
|
|
15
|
-
declare const jsonErrorHandler: (options?: JsonErrorHandlerOptions) => ErrorHandler;
|
|
16
|
-
|
|
17
|
-
export { jsonErrorHandler };
|
|
18
|
-
export type { JsonErrorBody, JsonErrorFormatter, JsonErrorHandlerOptions };
|
|
14
|
+
export declare const jsonErrorHandler: (options?: JsonErrorHandlerOptions) => ErrorHandler;
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import 'node:http';
|
|
3
|
-
|
|
1
|
+
import type { ErrorHandler } from "./types.d.d.ts";
|
|
4
2
|
declare const jsonapiErrorHandler: ErrorHandler;
|
|
5
|
-
|
|
6
|
-
export { jsonapiErrorHandler as default };
|
|
3
|
+
export default jsonapiErrorHandler;
|
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
import { IncomingMessage, ServerResponse } from
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
type
|
|
5
|
-
type JsonpErrorFormatter = (parameters: {
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
+
import type { ErrorHandler } from "./types.d.d.ts";
|
|
3
|
+
export type JsonpErrorBody = Record<string, unknown> | unknown[];
|
|
4
|
+
export type JsonpErrorFormatter = (parameters: {
|
|
6
5
|
error: Error;
|
|
7
6
|
reasonPhrase: string;
|
|
8
7
|
request: IncomingMessage;
|
|
9
8
|
response: ServerResponse;
|
|
10
9
|
statusCode: number;
|
|
11
10
|
}) => JsonpErrorBody | Promise<JsonpErrorBody>;
|
|
12
|
-
type JsonpErrorHandlerOptions = {
|
|
11
|
+
export type JsonpErrorHandlerOptions = {
|
|
13
12
|
callbackParamName?: string;
|
|
14
13
|
formatter?: JsonpErrorFormatter;
|
|
15
14
|
};
|
|
16
|
-
declare const jsonpErrorHandler: (options?: JsonpErrorHandlerOptions) => ErrorHandler;
|
|
17
|
-
|
|
18
|
-
export { jsonpErrorHandler };
|
|
19
|
-
export type { JsonpErrorBody, JsonpErrorFormatter, JsonpErrorHandlerOptions };
|
|
15
|
+
export declare const jsonpErrorHandler: (options?: JsonpErrorHandlerOptions) => ErrorHandler;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type { ErrorHandler } from "./types.d.d.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Normalizes errors according to the API Problem spec (RFC 7807).
|
|
4
|
+
* @see https://tools.ietf.org/html/rfc7807
|
|
5
|
+
*/
|
|
4
6
|
declare const problemErrorHandler: ErrorHandler;
|
|
5
|
-
|
|
6
|
-
export { problemErrorHandler as default };
|
|
7
|
+
export default problemErrorHandler;
|
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
import { IncomingMessage, ServerResponse } from
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
type TextErrorFormatter = (parameters: {
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
+
import type { ErrorHandler } from "./types.d.d.ts";
|
|
3
|
+
export type TextErrorFormatter = (parameters: {
|
|
5
4
|
error: Error;
|
|
6
5
|
reasonPhrase: string;
|
|
7
6
|
request: IncomingMessage;
|
|
8
7
|
response: ServerResponse;
|
|
9
8
|
statusCode: number;
|
|
10
9
|
}) => string | Promise<string>;
|
|
11
|
-
type TextErrorHandlerOptions = {
|
|
10
|
+
export type TextErrorHandlerOptions = {
|
|
12
11
|
formatter?: TextErrorFormatter;
|
|
13
12
|
};
|
|
14
|
-
declare const textErrorHandler: (options?: TextErrorHandlerOptions) => ErrorHandler;
|
|
15
|
-
|
|
16
|
-
export { textErrorHandler };
|
|
17
|
-
export type { TextErrorFormatter, TextErrorHandlerOptions };
|
|
13
|
+
export declare const textErrorHandler: (options?: TextErrorHandlerOptions) => ErrorHandler;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ServerResponse } from "node:http";
|
|
2
|
+
/**
|
|
3
|
+
* Send `JSON` object
|
|
4
|
+
* @param response response object
|
|
5
|
+
* @param jsonBody of data
|
|
6
|
+
* @param contentType optional content-type header value
|
|
7
|
+
*/
|
|
8
|
+
export declare const sendJson: (response: ServerResponse, jsonBody: unknown, contentType?: string) => void;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import { IncomingMessage, ServerResponse } from
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
type
|
|
5
|
-
type XmlErrorFormatter = (parameters: {
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
+
import type { ErrorHandler } from "./types.d.d.ts";
|
|
3
|
+
export type XmlErrorBody = Record<string, unknown> | unknown[];
|
|
4
|
+
export type XmlErrorFormatter = (parameters: {
|
|
6
5
|
error: Error;
|
|
7
6
|
reasonPhrase: string;
|
|
8
7
|
request: IncomingMessage;
|
|
9
8
|
response: ServerResponse;
|
|
10
9
|
statusCode: number;
|
|
11
10
|
}) => XmlErrorBody | Promise<XmlErrorBody>;
|
|
12
|
-
type ToXmlOptions = {
|
|
11
|
+
export type ToXmlOptions = {
|
|
13
12
|
attributeExplicitTrue?: boolean;
|
|
14
13
|
attributeFilter?: (key: string, value: unknown) => boolean;
|
|
15
14
|
attributeReplacements?: Record<string, string>;
|
|
@@ -19,12 +18,9 @@ type ToXmlOptions = {
|
|
|
19
18
|
indent?: string;
|
|
20
19
|
selfCloseTags?: boolean;
|
|
21
20
|
};
|
|
22
|
-
type XmlErrorHandlerOptions = {
|
|
21
|
+
export type XmlErrorHandlerOptions = {
|
|
23
22
|
formatter?: XmlErrorFormatter;
|
|
24
23
|
toXml?: ToXmlOptions;
|
|
25
24
|
xmlHeader?: boolean;
|
|
26
25
|
};
|
|
27
|
-
declare const xmlErrorHandler: (options?: XmlErrorHandlerOptions) => ErrorHandler;
|
|
28
|
-
|
|
29
|
-
export { xmlErrorHandler };
|
|
30
|
-
export type { ToXmlOptions, XmlErrorBody, XmlErrorFormatter, XmlErrorHandlerOptions };
|
|
26
|
+
export declare const xmlErrorHandler: (options?: XmlErrorHandlerOptions) => ErrorHandler;
|
|
@@ -1,31 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
error: (...arguments_: unknown[]) => void;
|
|
6
|
-
log: (...arguments_: unknown[]) => void;
|
|
7
|
-
};
|
|
8
|
-
type ColorizeMethod = (value: string) => string;
|
|
9
|
-
type BaseCliOptions = {
|
|
10
|
-
solutionTitle?: string;
|
|
11
|
-
solutionFinders?: SolutionFinder[];
|
|
12
|
-
debug?: boolean;
|
|
13
|
-
} & Partial<Omit<RenderErrorOptions, "color">> & {
|
|
14
|
-
color?: {
|
|
15
|
-
codeFrame?: RenderErrorOptions["color"];
|
|
16
|
-
boxen?: {
|
|
17
|
-
headerTextColor?: ColorizeMethod;
|
|
18
|
-
textColor?: ColorizeMethod;
|
|
19
|
-
borderColor?: ColorizeMethod;
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
type CliHandlerOptions = BaseCliOptions & {
|
|
24
|
-
logger?: CliLogger;
|
|
25
|
-
};
|
|
26
|
-
declare const terminalOutput: (error: Error, options?: CliHandlerOptions) => Promise<void>;
|
|
27
|
-
|
|
28
|
-
declare const ansiHandler: (error: Error, options?: BaseCliOptions) => Promise<string>;
|
|
29
|
-
|
|
30
|
-
export { ansiHandler, terminalOutput as cliHandler };
|
|
31
|
-
export type { BaseCliOptions, CliHandlerOptions };
|
|
1
|
+
import type { BaseCliOptions } from "../../../../shared/utils/cli-error-builder.d.ts";
|
|
2
|
+
export type { BaseCliOptions, CliHandlerOptions } from "../../../../shared/utils/cli-error-builder.d.ts";
|
|
3
|
+
export declare const ansiHandler: (error: Error, options?: BaseCliOptions) => Promise<string>;
|
|
4
|
+
export { terminalOutput as cliHandler } from "../../../../shared/utils/cli-error-builder.d.ts";
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var o=Object.defineProperty;var a=(r,e)=>o(r,"name",{value:e,configurable:!0});import{buildOutput as i}from"../packem_shared/cliHandler-
|
|
1
|
+
var o=Object.defineProperty;var a=(r,e)=>o(r,"name",{value:e,configurable:!0});import{buildOutput as i}from"../packem_shared/cliHandler-nqs3YWf5.js";import{terminalOutput as f}from"../packem_shared/cliHandler-nqs3YWf5.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
3
|
${n}`},"ansiHandler");export{d as ansiHandler,f as cliHandler};
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import { HtmlErrorHandlerOptions } from
|
|
2
|
-
import {
|
|
3
|
-
import 'node:http';
|
|
4
|
-
|
|
1
|
+
import type { HtmlErrorHandlerOptions } from "../../error-handler/html-error-handler.d.ts";
|
|
2
|
+
import type { FetchErrorHandlers } from "../../error-handler/types.d.d.ts";
|
|
5
3
|
declare const fetchHandler: (error: Error, options?: HtmlErrorHandlerOptions & {
|
|
6
4
|
extraHandlers?: FetchErrorHandlers;
|
|
7
5
|
onError?: (error: Error, request: Request) => void | Promise<void>;
|
|
8
6
|
showTrace?: boolean;
|
|
9
7
|
}) => Promise<(request: Request) => Promise<Response>>;
|
|
10
|
-
|
|
11
|
-
export { fetchHandler as default };
|
|
8
|
+
export default fetchHandler;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { IncomingMessage, ServerResponse } from
|
|
2
|
-
import { HtmlErrorHandlerOptions } from
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
+
import type { HtmlErrorHandlerOptions } from "../../error-handler/html-error-handler.d.ts";
|
|
3
|
+
import type { ErrorHandlers } from "../../error-handler/types.d.d.ts";
|
|
5
4
|
declare const nodeHandler: (error: Error, options?: HtmlErrorHandlerOptions & {
|
|
6
5
|
extraHandlers?: ErrorHandlers;
|
|
7
6
|
onError?: (error: Error, request: IncomingMessage, response: ServerResponse) => void | Promise<void>;
|
|
8
7
|
showTrace?: boolean;
|
|
9
8
|
}) => Promise<(request: IncomingMessage, response: ServerResponse) => Promise<void>>;
|
|
10
|
-
|
|
11
|
-
export { nodeHandler as default };
|
|
9
|
+
export default nodeHandler;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export { default as jsonapiErrorHandler } from
|
|
7
|
-
export { JsonpErrorBody, JsonpErrorFormatter, JsonpErrorHandlerOptions
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
10
|
-
export {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export {
|
|
1
|
+
export { default as createNegotiatedErrorHandler } from "./error-handler/create-negotiated-error-handler.d.ts";
|
|
2
|
+
export type { HtmlErrorHandlerOptions } from "./error-handler/html-error-handler.d.ts";
|
|
3
|
+
export { htmlErrorHandler } from "./error-handler/html-error-handler.d.ts";
|
|
4
|
+
export type { JsonErrorBody, JsonErrorFormatter, JsonErrorHandlerOptions } from "./error-handler/json-error-handler.d.ts";
|
|
5
|
+
export { jsonErrorHandler } from "./error-handler/json-error-handler.d.ts";
|
|
6
|
+
export { default as jsonapiErrorHandler } from "./error-handler/jsonapi-error-handler.d.ts";
|
|
7
|
+
export type { JsonpErrorBody, JsonpErrorFormatter, JsonpErrorHandlerOptions } from "./error-handler/jsonp-error-handler.d.ts";
|
|
8
|
+
export { jsonpErrorHandler } from "./error-handler/jsonp-error-handler.d.ts";
|
|
9
|
+
export { default as problemErrorHandler } from "./error-handler/problem-error-handler.d.ts";
|
|
10
|
+
export type { TextErrorFormatter, TextErrorHandlerOptions } from "./error-handler/text-error-handler.d.ts";
|
|
11
|
+
export { textErrorHandler } from "./error-handler/text-error-handler.d.ts";
|
|
12
|
+
export type { ApiFormat, ErrorHandler, ErrorHandlers } from "./error-handler/types.d.d.ts";
|
|
13
|
+
export type { ToXmlOptions, XmlErrorBody, XmlErrorFormatter, XmlErrorHandlerOptions } from "./error-handler/xml-error-handler.d.ts";
|
|
14
|
+
export { xmlErrorHandler } from "./error-handler/xml-error-handler.d.ts";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var j=Object.defineProperty;var c=(e,r)=>j(e,"name",{value:r,configurable:!0});import{createRequire as y}from"node:module";import{parseStacktrace as v}from"@visulima/error/stacktrace";import{boxen as x}from"@visulima/boxen";import{renderError as w}from"@visulima/error/error";import{ruleBasedFinder as F,errorHintFinder as B}from"@visulima/error/solution";const b=y(import.meta.url),u=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,p=c(e=>{if(typeof u<"u"&&u.versions&&u.versions.node){const[r,t]=u.versions.node.split(".").map(Number);if(r>22||r===22&&t>=3||r===20&&t>=16)return u.getBuiltinModule(e)}return b(e)},"__cjs_getBuiltinModule"),{readFile:_}=p("node:fs/promises"),{fileURLToPath:O}=p("node:url");var T=Object.defineProperty,A=c((e,r)=>T(e,"name",{value:r,configurable:!0}),"t");const q=["cjs","mjs"],P=["mdoc"],S=A(e=>{const r=(e.split("?")[0]??e).split(".").pop()?.toLowerCase();if(!r||q.includes(r))return"javascript";if(P.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,m=c((e,r)=>k(e,"name",{value:r,configurable:!0}),"o");const l=new Map,L=m(async e=>{if(/^(?:http|https|file|data):/.test(e)){if(l.has(e))return l.get(e);if(e.startsWith("file:"))try{const r=O(e),t=await _(r,"utf8");return l.set(e,t),t}catch{return}try{const r=await fetch(e);if(!r.ok)return;const t=await r.text();return l.set(e,t),t}catch{return}}},"getFileSource");m(()=>{l.clear()},"clearFileSourceCache");var C=Object.defineProperty,f=c((e,r)=>C(e,"name",{value:r,configurable:!0}),"d");const M=f(e=>e.replace(/^\s*#+\s*/,"").trim(),"sanitizeTitle"),R=f(async(e,r,t=!1)=>{const a=[...r,F,B],s=v(e,{frameLimit:1})[0]??{};for await(const o of a.sort((i,n)=>i.priority-n.priority)){const{handle:i}=o;if(typeof i!="function")continue;const n=await i(e,{file:s.file??"",language:S(s.file??""),line:s.line??0,snippet:s.file?await L(s.file):""});if(n)return n}},"runSolutionFinders"),$=f(async(e,r)=>{const{solutionFinders:t=[],solutionTitle:a,color:s,debug:o=!1,...i}=r,n=w(e,{...i,...s?.codeFrame}),d=await R(e,t,o);if(!d)return{errorAnsi:n,solutionBox:void 0};const g=M(d.header??a??"A possible solution to this error"),h=x(d.body,{borderStyle:"round",padding:{top:1,right:2,bottom:1,left:2},margin:{top:0,right:0,bottom:0,left:0},headerText:`💡 ${g}`,headerAlignment:"left",textAlignment:"left",...s?.boxen});return{errorAnsi:n,solutionBox:h}},"buildOutput"),D=f(async(e,r={})=>{const{logger:t=console,...a}=r,{errorAnsi:s,solutionBox:o}=await $(e,a);t.error(s),o&&(t.log(""),t.log(o))},"terminalOutput");export{$ as buildOutput,D as terminalOutput};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visulima/error-handler",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"description": "Error handlers for use in development and production environments.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"visulima",
|
|
@@ -134,8 +134,8 @@
|
|
|
134
134
|
],
|
|
135
135
|
"dependencies": {
|
|
136
136
|
"@tinyhttp/accepts": "^2.2.4",
|
|
137
|
-
"@visulima/boxen": "2.0.
|
|
138
|
-
"@visulima/error": "5.0.
|
|
137
|
+
"@visulima/boxen": "2.0.9",
|
|
138
|
+
"@visulima/error": "5.0.5",
|
|
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 j=Object.defineProperty;var c=(e,r)=>j(e,"name",{value:r,configurable:!0});import{createRequire as y}from"node:module";import{parseStacktrace as b}from"@visulima/error/stacktrace";import{boxen as v}from"@visulima/boxen";import{renderError as x}from"@visulima/error/error";import{ruleBasedFinder as O,errorHintFinder as B}from"@visulima/error/solution";const h=y(import.meta.url),u=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,p=c(e=>{if(typeof u<"u"&&u.versions&&u.versions.node){const[r,t]=u.versions.node.split(".").map(Number);if(r>22||r===22&&t>=3||r===20&&t>=16)return u.getBuiltinModule(e)}return h(e)},"__cjs_getBuiltinModule"),{readFile:w}=p("node:fs/promises"),{fileURLToPath:_}=p("node:url");var F=Object.defineProperty,T=c((e,r)=>F(e,"name",{value:r,configurable:!0}),"t");const A=["cjs","mjs"],q=["mdoc"],P=T(e=>{const r=(e.split("?")[0]??e).split(".").pop()?.toLowerCase();if(!r||A.includes(r))return"javascript";if(q.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=c((e,r)=>k(e,"name",{value:r,configurable:!0}),"s");const l=new Map,S=L(async e=>{if(/^(?:http|https|file|data):/.test(e)){if(l.has(e))return l.get(e);if(e.startsWith("file:"))try{const r=_(e),t=await w(r,"utf8");return l.set(e,t),t}catch{return}try{const r=await fetch(e);if(!r.ok)return;const t=await r.text();return l.set(e,t),t}catch{return}}},"getFileSource");var M=Object.defineProperty,f=c((e,r)=>M(e,"name",{value:r,configurable:!0}),"d");const R=f(e=>e.replace(/^\s*#+\s*/,"").trim(),"sanitizeTitle"),$=f(async(e,r,t=!1)=>{const a=[...r,O,B],s=b(e,{frameLimit:1})[0]??{};for await(const o of a.sort((i,n)=>i.priority-n.priority)){const{handle:i}=o;if(typeof i!="function")continue;const n=await i(e,{file:s.file??"",language:P(s.file??""),line:s.line??0,snippet:s.file?await S(s.file):""});if(n)return n}},"runSolutionFinders"),C=f(async(e,r)=>{const{solutionFinders:t=[],solutionTitle:a,color:s,debug:o=!1,...i}=r,n=x(e,{...i,...s?.codeFrame}),d=await $(e,t,o);if(!d)return{errorAnsi:n,solutionBox:void 0};const m=R(d.header??a??"A possible solution to this error"),g=v(d.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:g}},"buildOutput"),D=f(async(e,r={})=>{const{logger:t=console,...a}=r,{errorAnsi:s,solutionBox:o}=await C(e,a);t.error(s),o&&(t.log(""),t.log(o))},"terminalOutput");export{C as buildOutput,D as terminalOutput};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
-
|
|
3
|
-
type ErrorHandler = <Request extends IncomingMessage, Response extends ServerResponse>(
|
|
4
|
-
error: Error,
|
|
5
|
-
request: Request,
|
|
6
|
-
response: Response,
|
|
7
|
-
) => Promise<void> | void;
|
|
8
|
-
|
|
9
|
-
type FetchErrorHandler = (error: unknown, request: Request) => Promise<Response>;
|
|
10
|
-
|
|
11
|
-
type ErrorHandlers = {
|
|
12
|
-
handler: ErrorHandler;
|
|
13
|
-
regex: RegExp;
|
|
14
|
-
}[];
|
|
15
|
-
|
|
16
|
-
type FetchErrorHandlers = {
|
|
17
|
-
handler: FetchErrorHandler;
|
|
18
|
-
regex: RegExp;
|
|
19
|
-
}[];
|
|
20
|
-
|
|
21
|
-
type ApiFormat = "jsonapi" | "problem" | "html";
|
|
22
|
-
|
|
23
|
-
export type { ApiFormat as A, ErrorHandlers as E, FetchErrorHandlers as F, ErrorHandler as a };
|