From ca4b09685bc25451c901d3fae8700da9b966d27c Mon Sep 17 00:00:00 2001 From: Damian Glowala Date: Thu, 2 Nov 2023 19:18:56 +0100 Subject: [PATCH 1/4] feat: add optional generic param for `H3Error` data --- src/error.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/error.ts b/src/error.ts index 37d985cc..b484d15b 100644 --- a/src/error.ts +++ b/src/error.ts @@ -15,17 +15,17 @@ import { hasProp } from "./utils/internal/object"; * @property {string} statusMessage - A string representing the HTTP status message. * @property {boolean} fatal - Indicates if the error is a fatal error. * @property {boolean} unhandled - Indicates if the error was unhandled and auto captured. - * @property {any} data - An extra data that will be included in the response. + * @property {DataT} data - An extra data that will be included in the response. * This can be used to pass additional information about the error. * @property {boolean} internal - Setting this property to `true` will mark the error as an internal error. */ -export class H3Error extends Error { +export class H3Error extends Error { static __h3_error__ = true; statusCode = 500; fatal = false; unhandled = false; statusMessage?: string; - data?: any; + data?: DataT; cause?: unknown; constructor(message: string, opts: { cause?: unknown } = {}) { From 2673ba4739d6ce09967587af89cac0d7793b2eb6 Mon Sep 17 00:00:00 2001 From: Damian Glowala Date: Thu, 2 Nov 2023 21:25:48 +0100 Subject: [PATCH 2/4] chore: add generic param in `toJSON` --- src/error.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/error.ts b/src/error.ts index b484d15b..7884d244 100644 --- a/src/error.ts +++ b/src/error.ts @@ -40,7 +40,7 @@ export class H3Error extends Error { toJSON() { const obj: Pick< - H3Error, + H3Error, "message" | "statusCode" | "statusMessage" | "data" > = { message: this.message, From 80f3b235c7cd831abb127b1178bcae4c4efe3171 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20G=C5=82owala?= Date: Fri, 3 Nov 2023 10:48:24 +0100 Subject: [PATCH 3/4] feat: add optional generic param to `createError` --- src/error.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/error.ts b/src/error.ts index 7884d244..f3c17470 100644 --- a/src/error.ts +++ b/src/error.ts @@ -64,18 +64,18 @@ export class H3Error extends Error { * @param input {string | (Partial & { status?: number; statusText?: string })} - The error message or an object containing error properties. * @return {H3Error} - An instance of H3Error. */ -export function createError( - input: string | (Partial & { status?: number; statusText?: string }), +export function createError( + input: string | (Partial> & { status?: number; statusText?: string }), ): H3Error { if (typeof input === "string") { - return new H3Error(input); + return new H3Error(input); } if (isError(input)) { return input; } - const err = new H3Error(input.message ?? input.statusMessage ?? "", { + const err = new H3Error(input.message ?? input.statusMessage ?? "", { cause: input.cause || input, }); From be202124d0487d68f799556e7379a8cdf4fb2c8c Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Fri, 3 Nov 2023 10:16:33 +0000 Subject: [PATCH 4/4] chore: apply automated lint fixes --- src/error.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/error.ts b/src/error.ts index f3c17470..441dbc03 100644 --- a/src/error.ts +++ b/src/error.ts @@ -65,7 +65,9 @@ export class H3Error extends Error { * @return {H3Error} - An instance of H3Error. */ export function createError( - input: string | (Partial> & { status?: number; statusText?: string }), + input: + | string + | (Partial> & { status?: number; statusText?: string }), ): H3Error { if (typeof input === "string") { return new H3Error(input);