framework-do-dede 3.0.35 → 3.0.37

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.
@@ -1,5 +1,6 @@
1
1
  import { InternalServerError, ServerError } from "../http";
2
2
  import { flushControllers, getControllers } from "../application/controller";
3
+ import { CustomServerError } from "./errors/server";
3
4
  export default class ControllerHandler {
4
5
  constructor(httpServer, port) {
5
6
  for (const { handler, middlewares, method, route, statusCode, params, query, headers, responseType } of this.registryControllers()) {
@@ -37,6 +38,9 @@ export default class ControllerHandler {
37
38
  capturedError = this.extractError(error, httpServer);
38
39
  input.setStatus(capturedError.statusCode);
39
40
  endTime = performance.now();
41
+ if (capturedError?.custom) {
42
+ return capturedError;
43
+ }
40
44
  return {
41
45
  message: capturedError.message,
42
46
  statusCode: capturedError.statusCode
@@ -150,6 +154,13 @@ export default class ControllerHandler {
150
154
  statusCode: error.getStatusCode()
151
155
  };
152
156
  }
157
+ if (error instanceof CustomServerError) {
158
+ return {
159
+ ...error.getCustom(),
160
+ statusCode: error.getStatusCode(),
161
+ custom: true
162
+ };
163
+ }
153
164
  const debugError = {
154
165
  sourceUrl: error.sourceURL,
155
166
  line: error.line,
@@ -3,6 +3,13 @@ export declare abstract class ServerError extends Error {
3
3
  constructor(message: string, statusCode: number);
4
4
  getStatusCode(): number;
5
5
  }
6
+ export declare class CustomServerError extends Error {
7
+ private statusCode;
8
+ private custom;
9
+ constructor(custom: any, statusCode: number, nameError?: string);
10
+ getStatusCode(): number;
11
+ getCustom(): any;
12
+ }
6
13
  export declare class NotFound extends ServerError {
7
14
  constructor(message: string);
8
15
  }
@@ -9,6 +9,22 @@ export class ServerError extends Error {
9
9
  return this.statusCode;
10
10
  }
11
11
  }
12
+ export class CustomServerError extends Error {
13
+ statusCode;
14
+ custom;
15
+ constructor(custom, statusCode, nameError = '') {
16
+ super();
17
+ this.name = nameError || this.constructor.name;
18
+ this.statusCode = statusCode;
19
+ this.custom = custom;
20
+ }
21
+ getStatusCode() {
22
+ return this.statusCode;
23
+ }
24
+ getCustom() {
25
+ return this.custom;
26
+ }
27
+ }
12
28
  export class NotFound extends ServerError {
13
29
  constructor(message) {
14
30
  super(message, 404);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "framework-do-dede",
3
- "version": "3.0.35",
3
+ "version": "3.0.37",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",