framework-do-dede 3.0.35 → 3.0.36

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()) {
@@ -150,6 +151,12 @@ export default class ControllerHandler {
150
151
  statusCode: error.getStatusCode()
151
152
  };
152
153
  }
154
+ if (error instanceof CustomServerError) {
155
+ return {
156
+ ...error.getCustom(),
157
+ statusCode: error.getStatusCode()
158
+ };
159
+ }
153
160
  const debugError = {
154
161
  sourceUrl: error.sourceURL,
155
162
  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.36",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",