@ogcio/fastify-error-handler 5.1.0 → 5.2.0
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/__tests__/initialize-error-handler.test.ts +4 -0
- package/__tests__/life-events-error-handler.test.ts +11 -3
- package/dist/initialize-error-handler.d.ts +2 -1
- package/dist/initialize-error-handler.d.ts.map +1 -1
- package/dist/initialize-error-handler.js +9 -4
- package/dist/initialize-error-handler.js.map +1 -1
- package/package.json +5 -4
- package/src/initialize-error-handler.ts +19 -13
- package/vitest.config.mts +2 -3
|
@@ -28,6 +28,7 @@ describe("Error management", () => {
|
|
|
28
28
|
detail: "error message",
|
|
29
29
|
requestId: "req-1",
|
|
30
30
|
name: "FastifyError",
|
|
31
|
+
statusCode: 500,
|
|
31
32
|
});
|
|
32
33
|
});
|
|
33
34
|
|
|
@@ -57,6 +58,7 @@ describe("Error management", () => {
|
|
|
57
58
|
},
|
|
58
59
|
},
|
|
59
60
|
],
|
|
61
|
+
statusCode: 422,
|
|
60
62
|
});
|
|
61
63
|
});
|
|
62
64
|
|
|
@@ -75,6 +77,7 @@ describe("Error management", () => {
|
|
|
75
77
|
detail: "error message",
|
|
76
78
|
requestId: "req-1",
|
|
77
79
|
name: "FastifyError",
|
|
80
|
+
statusCode: 500,
|
|
78
81
|
});
|
|
79
82
|
});
|
|
80
83
|
|
|
@@ -92,6 +95,7 @@ describe("Error management", () => {
|
|
|
92
95
|
detail: "Route not found: /this-path-does-not-exist",
|
|
93
96
|
requestId: "req-1",
|
|
94
97
|
name: new httpErrors[404]("TEMP").name,
|
|
98
|
+
statusCode: 404,
|
|
95
99
|
});
|
|
96
100
|
});
|
|
97
101
|
});
|
|
@@ -39,11 +39,15 @@ describe("Error management", () => {
|
|
|
39
39
|
|
|
40
40
|
assert.ok(typeof response !== "undefined");
|
|
41
41
|
assert.equal(response?.statusCode, errorProv.expectedStatusCode);
|
|
42
|
+
const parsedErrorClass = sharedErrors.parseHttpErrorClass(
|
|
43
|
+
errorProv.expectedStatusCode,
|
|
44
|
+
);
|
|
42
45
|
assert.deepEqual(response.json(), {
|
|
43
|
-
code:
|
|
46
|
+
code: parsedErrorClass.errorClass,
|
|
44
47
|
detail: "Failed Correctly!",
|
|
45
48
|
requestId: "req-1",
|
|
46
49
|
name: errorInstance.name,
|
|
50
|
+
statusCode: parsedErrorClass.statusCode,
|
|
47
51
|
});
|
|
48
52
|
});
|
|
49
53
|
}
|
|
@@ -58,11 +62,13 @@ describe("Error management", () => {
|
|
|
58
62
|
|
|
59
63
|
assert.ok(typeof response !== "undefined");
|
|
60
64
|
assert.equal(response?.statusCode, 503);
|
|
65
|
+
const parsedErrorClass = sharedErrors.parseHttpErrorClass(503);
|
|
61
66
|
assert.deepEqual(response.json(), {
|
|
62
|
-
code:
|
|
67
|
+
code: parsedErrorClass.errorClass,
|
|
63
68
|
detail: "message",
|
|
64
69
|
requestId: "req-1",
|
|
65
70
|
name: new httpErrors[503]("MOCK").name,
|
|
71
|
+
statusCode: parsedErrorClass.statusCode,
|
|
66
72
|
});
|
|
67
73
|
});
|
|
68
74
|
|
|
@@ -75,14 +81,16 @@ describe("Error management", () => {
|
|
|
75
81
|
|
|
76
82
|
assert.ok(typeof response !== "undefined");
|
|
77
83
|
assert.equal(response?.statusCode, 422);
|
|
84
|
+
const parsedErrorClass = sharedErrors.parseHttpErrorClass(422);
|
|
78
85
|
assert.deepEqual(response.json(), {
|
|
79
|
-
code:
|
|
86
|
+
code: parsedErrorClass.errorClass,
|
|
80
87
|
detail: "message",
|
|
81
88
|
requestId: "req-1",
|
|
82
89
|
name: new httpErrors[422]("MOCK").name,
|
|
83
90
|
validation: [
|
|
84
91
|
{ fieldName: "field", message: "error", validationRule: "equal" },
|
|
85
92
|
],
|
|
93
|
+
statusCode: parsedErrorClass.statusCode,
|
|
86
94
|
});
|
|
87
95
|
});
|
|
88
96
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { FastifyInstance } from "fastify";
|
|
2
1
|
import { type HttpErrorClasses, type ValidationErrorData } from "@ogcio/shared-errors";
|
|
2
|
+
import type { FastifyInstance } from "fastify";
|
|
3
3
|
export interface OutputHttpError {
|
|
4
4
|
code: HttpErrorClasses;
|
|
5
5
|
detail: string;
|
|
@@ -7,6 +7,7 @@ export interface OutputHttpError {
|
|
|
7
7
|
name: string;
|
|
8
8
|
validation?: ValidationErrorData[];
|
|
9
9
|
process?: string;
|
|
10
|
+
statusCode: number;
|
|
10
11
|
}
|
|
11
12
|
export declare const setupErrorHandler: (server: FastifyInstance) => void;
|
|
12
13
|
export declare const initializeNotFoundHandler: (server: FastifyInstance) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initialize-error-handler.d.ts","sourceRoot":"","sources":["../src/initialize-error-handler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"initialize-error-handler.d.ts","sourceRoot":"","sources":["../src/initialize-error-handler.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EAEzB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAEV,eAAe,EAGhB,MAAM,SAAS,CAAC;AAIjB,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,gBAAgB,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,mBAAmB,EAAE,CAAC;IACnC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;CACpB;AAOD,eAAO,MAAM,iBAAiB,WAAY,eAAe,KAAG,IAyC3D,CAAC;AAIF,eAAO,MAAM,yBAAyB,WAAY,eAAe,KAAG,IAUnE,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { httpErrors } from "@fastify/sensible";
|
|
2
|
+
import { LogMessages, getLoggingContextError, setLoggingContext, } from "@ogcio/fastify-logging-wrapper";
|
|
2
3
|
import { parseHttpErrorClass, } from "@ogcio/shared-errors";
|
|
3
4
|
import { isHttpError } from "http-errors";
|
|
4
|
-
import { httpErrors } from "@fastify/sensible";
|
|
5
5
|
// The error handler below is the same as the original one in Fastify,
|
|
6
6
|
// just without unwanted log entries
|
|
7
7
|
// I've opened an issue to fastify to ask them if we could avoid logging
|
|
@@ -77,11 +77,13 @@ const getValidationFromFastifyError = (validationInput) => {
|
|
|
77
77
|
return { validation: output };
|
|
78
78
|
};
|
|
79
79
|
const getResponseFromFastifyError = (error, request) => {
|
|
80
|
+
const errorDetails = parseHttpErrorClass(error.statusCode);
|
|
80
81
|
const output = {
|
|
81
|
-
code:
|
|
82
|
+
code: errorDetails.errorClass,
|
|
82
83
|
detail: error.message,
|
|
83
84
|
requestId: request.id,
|
|
84
85
|
name: error.name,
|
|
86
|
+
statusCode: errorDetails.statusCode,
|
|
85
87
|
};
|
|
86
88
|
if (error.validation && error.validation.length > 0) {
|
|
87
89
|
output.validation = getValidationFromFastifyError(error.validation).validation;
|
|
@@ -91,12 +93,14 @@ const getResponseFromFastifyError = (error, request) => {
|
|
|
91
93
|
const manageHttpError = (error, request, reply) => {
|
|
92
94
|
reply.raw.statusCode = error.statusCode;
|
|
93
95
|
reply.statusCode = error.statusCode;
|
|
96
|
+
const errorDetails = parseHttpErrorClass(error.statusCode);
|
|
94
97
|
const errorResponse = {
|
|
95
|
-
code:
|
|
98
|
+
code: errorDetails.errorClass,
|
|
96
99
|
detail: error.message,
|
|
97
100
|
requestId: request.id,
|
|
98
101
|
name: error.name,
|
|
99
102
|
process: error.errorProcess,
|
|
103
|
+
statusCode: errorDetails.statusCode,
|
|
100
104
|
};
|
|
101
105
|
let validationErrors = error.validationErrors && error.validationErrors.length > 0
|
|
102
106
|
? error.validationErrors
|
|
@@ -107,6 +111,7 @@ const manageHttpError = (error, request, reply) => {
|
|
|
107
111
|
if (validationErrors) {
|
|
108
112
|
errorResponse.validation = validationErrors;
|
|
109
113
|
}
|
|
114
|
+
console.log({ errorResponse, errorDetails });
|
|
110
115
|
reply.status(error.statusCode).send(errorResponse);
|
|
111
116
|
};
|
|
112
117
|
const toOutputHttpValidationError = (error) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initialize-error-handler.js","sourceRoot":"","sources":["../src/initialize-error-handler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"initialize-error-handler.js","sourceRoot":"","sources":["../src/initialize-error-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EACL,WAAW,EACX,sBAAsB,EACtB,iBAAiB,GAClB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAGL,mBAAmB,GACpB,MAAM,sBAAsB,CAAC;AAQ9B,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAY1C,sEAAsE;AACtE,oCAAoC;AACpC,wEAAwE;AACxE,mDAAmD;AACnD,iDAAiD;AACjD,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,MAAuB,EAAQ,EAAE;IACjE,MAAM,eAAe,GAAG,CACtB,KAIC,EACD,KAAmB,EACnB,EAAE;QACF,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC;QACtB,IAAI,UAAU,GAAG,GAAG,CAAC,UAAU,CAAC;QAChC,UAAU,GAAG,UAAU,IAAI,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC;QAClD,mCAAmC;QACnC,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;YAClB,IAAI,KAAK,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;gBAChC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAC/B,CAAC;YACD,IAAI,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,MAAM,IAAI,GAAG,EAAE,CAAC;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AAC;QACrB,aAAa,CAAC,UAAU,GAAG,gBAAgB,CAAC;IAC9C,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,EAAE,aAAa,EAAE,YAAY,EAAE,CAAC,CAAC;IAC7C,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;AACrD,CAAC,CAAC;AAEF,MAAM,2BAA2B,GAAG,CAAC,KAAmB,EAAa,EAAE;IACrE,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC;QACtB,MAAM,UAAU,CAAC,WAAW,CAAC,GAAG,EAAE,gCAAgC,CAAC,CAAC;IACtE,CAAC;IAED,OAAO,UAAU,CAAC,WAAW,CAC3B,GAAG,EACH,KAAK,CAAC,OAAO,EACb,6BAA6B,CAAC,KAAK,CAAC,UAAU,CAAC,CAChD,CAAC;AACJ,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ogcio/fastify-error-handler",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "rm -rf dist tsconfig.prod.tsbuildinfo tsconfig.tsbuildinfo && tsc -p tsconfig.prod.json",
|
|
9
|
-
"test": "vitest run --coverage --outputFile=results.xml"
|
|
9
|
+
"test": "vitest run --coverage --outputFile=results.xml",
|
|
10
|
+
"prepublishOnly": "npm i && npm run build && npm run test"
|
|
10
11
|
},
|
|
11
12
|
"keywords": [],
|
|
12
13
|
"author": {
|
|
@@ -17,8 +18,8 @@
|
|
|
17
18
|
"description": "Normalize the error handling of errors with related logs",
|
|
18
19
|
"dependencies": {
|
|
19
20
|
"@ogcio/fastify-logging-wrapper": "^5.0.2",
|
|
20
|
-
"@ogcio/shared-errors": "^1.
|
|
21
|
-
"fastify": "^5.
|
|
21
|
+
"@ogcio/shared-errors": "^1.1.0",
|
|
22
|
+
"fastify": "^5.1.0"
|
|
22
23
|
},
|
|
23
24
|
"devDependencies": {
|
|
24
25
|
"@types/http-errors": "^2.0.4"
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import type
|
|
2
|
-
FastifyError,
|
|
3
|
-
FastifyRequest,
|
|
4
|
-
FastifyInstance,
|
|
5
|
-
FastifyReply,
|
|
6
|
-
} from "fastify";
|
|
7
|
-
import type { FastifySchemaValidationError } from "fastify/types/schema.js";
|
|
1
|
+
import { type HttpError, httpErrors } from "@fastify/sensible";
|
|
8
2
|
import {
|
|
9
|
-
setLoggingContext,
|
|
10
|
-
getLoggingContextError,
|
|
11
3
|
LogMessages,
|
|
4
|
+
getLoggingContextError,
|
|
5
|
+
setLoggingContext,
|
|
12
6
|
} from "@ogcio/fastify-logging-wrapper";
|
|
13
7
|
import {
|
|
14
8
|
type HttpErrorClasses,
|
|
15
9
|
type ValidationErrorData,
|
|
16
10
|
parseHttpErrorClass,
|
|
17
11
|
} from "@ogcio/shared-errors";
|
|
12
|
+
import type {
|
|
13
|
+
FastifyError,
|
|
14
|
+
FastifyInstance,
|
|
15
|
+
FastifyReply,
|
|
16
|
+
FastifyRequest,
|
|
17
|
+
} from "fastify";
|
|
18
|
+
import type { FastifySchemaValidationError } from "fastify/types/schema.js";
|
|
18
19
|
import { isHttpError } from "http-errors";
|
|
19
|
-
import { type HttpError, httpErrors } from "@fastify/sensible";
|
|
20
20
|
|
|
21
21
|
export interface OutputHttpError {
|
|
22
22
|
code: HttpErrorClasses;
|
|
@@ -25,6 +25,7 @@ export interface OutputHttpError {
|
|
|
25
25
|
name: string;
|
|
26
26
|
validation?: ValidationErrorData[];
|
|
27
27
|
process?: string;
|
|
28
|
+
statusCode: number;
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
// The error handler below is the same as the original one in Fastify,
|
|
@@ -123,11 +124,14 @@ const getResponseFromFastifyError = (
|
|
|
123
124
|
error: FastifyError,
|
|
124
125
|
request: FastifyRequest,
|
|
125
126
|
): OutputHttpError => {
|
|
127
|
+
const errorDetails = parseHttpErrorClass(error.statusCode);
|
|
128
|
+
|
|
126
129
|
const output: OutputHttpError = {
|
|
127
|
-
code:
|
|
130
|
+
code: errorDetails.errorClass,
|
|
128
131
|
detail: error.message,
|
|
129
132
|
requestId: request.id,
|
|
130
133
|
name: error.name,
|
|
134
|
+
statusCode: errorDetails.statusCode,
|
|
131
135
|
};
|
|
132
136
|
if (error.validation && error.validation.length > 0) {
|
|
133
137
|
output.validation = getValidationFromFastifyError(
|
|
@@ -145,12 +149,14 @@ const manageHttpError = (
|
|
|
145
149
|
): void => {
|
|
146
150
|
reply.raw.statusCode = error.statusCode;
|
|
147
151
|
reply.statusCode = error.statusCode;
|
|
152
|
+
const errorDetails = parseHttpErrorClass(error.statusCode);
|
|
148
153
|
const errorResponse: OutputHttpError = {
|
|
149
|
-
code:
|
|
154
|
+
code: errorDetails.errorClass,
|
|
150
155
|
detail: error.message,
|
|
151
156
|
requestId: request.id,
|
|
152
157
|
name: error.name,
|
|
153
158
|
process: error.errorProcess,
|
|
159
|
+
statusCode: errorDetails.statusCode,
|
|
154
160
|
};
|
|
155
161
|
let validationErrors =
|
|
156
162
|
error.validationErrors && error.validationErrors.length > 0
|
|
@@ -163,7 +169,7 @@ const manageHttpError = (
|
|
|
163
169
|
if (validationErrors) {
|
|
164
170
|
errorResponse.validation = validationErrors;
|
|
165
171
|
}
|
|
166
|
-
|
|
172
|
+
console.log({ errorResponse, errorDetails });
|
|
167
173
|
reply.status(error.statusCode).send(errorResponse);
|
|
168
174
|
};
|
|
169
175
|
|
package/vitest.config.mts
CHANGED
|
@@ -2,12 +2,11 @@ import { defineConfig } from "vitest/config";
|
|
|
2
2
|
|
|
3
3
|
export default defineConfig({
|
|
4
4
|
test: {
|
|
5
|
-
reporters: "
|
|
5
|
+
reporters: "default",
|
|
6
6
|
coverage: {
|
|
7
|
-
reporter: ["text"],
|
|
7
|
+
reporter: ["text", "cobertura"],
|
|
8
8
|
provider: "istanbul",
|
|
9
9
|
},
|
|
10
|
-
|
|
11
10
|
include: [
|
|
12
11
|
"**/@(test?(s)|__test?(s)__)/**/*.test.@(js|cjs|mjs|tap|cts|jsx|mts|ts|tsx)",
|
|
13
12
|
"**/*.@(test?(s)|spec).@(js|cjs|mjs|tap|cts|jsx|mts|ts|tsx)",
|