framework-do-dede 3.0.34 → 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.
|
@@ -10,9 +10,8 @@ export class Entity {
|
|
|
10
10
|
continue;
|
|
11
11
|
if (value === undefined)
|
|
12
12
|
continue;
|
|
13
|
-
const valueIsZero = !isNaN(value) ? Number(value) === 0 : false;
|
|
14
13
|
// @ts-ignore
|
|
15
|
-
if (propertiesConfigs && propertiesConfigs[propName]?.serialize &&
|
|
14
|
+
if (propertiesConfigs && propertiesConfigs[propName]?.serialize && value) {
|
|
16
15
|
const serializedValue = propertiesConfigs[propName].serialize(value);
|
|
17
16
|
if (serializedValue && typeof serializedValue === 'object' && !Array.isArray(serializedValue)) {
|
|
18
17
|
const entries = Object.entries(serializedValue);
|
|
@@ -28,7 +27,7 @@ export class Entity {
|
|
|
28
27
|
value = serializedValue;
|
|
29
28
|
}
|
|
30
29
|
}
|
|
31
|
-
if (
|
|
30
|
+
if (value === undefined || value === null)
|
|
32
31
|
value = null;
|
|
33
32
|
result[propertyName] = value;
|
|
34
33
|
}
|
|
@@ -46,7 +45,6 @@ export class Entity {
|
|
|
46
45
|
if (value === undefined)
|
|
47
46
|
continue;
|
|
48
47
|
// @ts-ignore
|
|
49
|
-
const valueIsZero = !isNaN(value) ? Number(value) === 0 : false;
|
|
50
48
|
if (propertiesConfigs && propertiesConfigs[propName]?.serialize && (value || valueIsZero)) {
|
|
51
49
|
const serializedValue = await propertiesConfigs[propName].serialize(value);
|
|
52
50
|
if (serializedValue && typeof serializedValue === 'object' && !Array.isArray(serializedValue)) {
|
|
@@ -63,7 +61,7 @@ export class Entity {
|
|
|
63
61
|
value = serializedValue;
|
|
64
62
|
}
|
|
65
63
|
}
|
|
66
|
-
if (
|
|
64
|
+
if (value === undefined || value === null)
|
|
67
65
|
value = null;
|
|
68
66
|
result[propertyName] = value;
|
|
69
67
|
}
|
|
@@ -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);
|