quantum-flow 1.10.2 → 1.10.4
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.
|
@@ -139,7 +139,7 @@ class HttpServer {
|
|
|
139
139
|
if (isError) {
|
|
140
140
|
return this.handleError(data, request, response, startTime);
|
|
141
141
|
}
|
|
142
|
-
if (this.config.interceptor) {
|
|
142
|
+
if (this.config.interceptor && data) {
|
|
143
143
|
data = await this.config.interceptor(data, request, response);
|
|
144
144
|
}
|
|
145
145
|
return this.sendResponse(response, data, startTime);
|
|
@@ -186,7 +186,10 @@ class HttpServer {
|
|
|
186
186
|
const instance = new ControllerClass();
|
|
187
187
|
if (typeof instance.handleRequest === 'function') {
|
|
188
188
|
const data = await instance.handleRequest(request, response);
|
|
189
|
-
if (data
|
|
189
|
+
if (!data) {
|
|
190
|
+
return undefined;
|
|
191
|
+
}
|
|
192
|
+
if (data?.status !== 404) {
|
|
190
193
|
return data;
|
|
191
194
|
}
|
|
192
195
|
}
|
|
@@ -197,7 +200,7 @@ class HttpServer {
|
|
|
197
200
|
};
|
|
198
201
|
}
|
|
199
202
|
async sendResponse(res, data, startTime) {
|
|
200
|
-
|
|
203
|
+
console.log(data);
|
|
201
204
|
if (res.headersSent)
|
|
202
205
|
return;
|
|
203
206
|
if (!res.getHeader('Content-Type')) {
|
|
@@ -212,7 +215,7 @@ class HttpServer {
|
|
|
212
215
|
}
|
|
213
216
|
res.setHeader('X-Response-Time', `${Date.now() - startTime}ms`);
|
|
214
217
|
res.statusCode = data.status ?? 200;
|
|
215
|
-
res.end(JSON.stringify(
|
|
218
|
+
res.end(JSON.stringify(data.data));
|
|
216
219
|
}
|
|
217
220
|
async handleError(error, request, response, startTime) {
|
|
218
221
|
let errorResponse = {
|
|
@@ -223,22 +226,20 @@ class HttpServer {
|
|
|
223
226
|
stack: error.stack,
|
|
224
227
|
},
|
|
225
228
|
};
|
|
226
|
-
console.log(errorResponse);
|
|
227
229
|
if (!this.config.errorHandler) {
|
|
228
|
-
return this.sendResponse(response, errorResponse, startTime);
|
|
230
|
+
return this.sendResponse(response, (0, _utils_1.stringifyError)(errorResponse), startTime);
|
|
229
231
|
}
|
|
230
232
|
try {
|
|
231
233
|
const intercepted = await this.config.errorHandler(error, request, response);
|
|
232
|
-
|
|
233
|
-
if (
|
|
234
|
-
|
|
235
|
-
errorResponse.data = rest;
|
|
234
|
+
let data = intercepted.data ?? intercepted;
|
|
235
|
+
if (data instanceof Error) {
|
|
236
|
+
data = (0, _utils_1.stringifyError)(data);
|
|
236
237
|
}
|
|
237
238
|
errorResponse.status = intercepted.status ?? errorResponse.status;
|
|
238
|
-
errorResponse.data =
|
|
239
|
+
errorResponse.data = data;
|
|
239
240
|
}
|
|
240
241
|
catch (cathed) {
|
|
241
|
-
Object.assign(errorResponse, cathed);
|
|
242
|
+
Object.assign(errorResponse, (0, _utils_1.stringifyError)(cathed));
|
|
242
243
|
}
|
|
243
244
|
return this.sendResponse(response, errorResponse, startTime);
|
|
244
245
|
}
|
package/dist/core/Controller.js
CHANGED
|
@@ -99,7 +99,7 @@ function Controller(config, middlewares = []) {
|
|
|
99
99
|
subPath: Reflect.getMetadata(_constants_1.ROUTE_PREFIX, proto) || '',
|
|
100
100
|
};
|
|
101
101
|
const result = await this.routeWalker(context, request, response);
|
|
102
|
-
return result
|
|
102
|
+
return result === null ? { status: 404, message: 'Method Not Found' } : result;
|
|
103
103
|
};
|
|
104
104
|
async routeWalker(context, request, response) {
|
|
105
105
|
const { controllerInstance, controllerMeta, path, method, subPath } = context;
|
|
@@ -185,6 +185,9 @@ function Controller(config, middlewares = []) {
|
|
|
185
185
|
response: response,
|
|
186
186
|
request: request,
|
|
187
187
|
}).catch((err) => err);
|
|
188
|
+
if (!apiResponse) {
|
|
189
|
+
return { status: 200 };
|
|
190
|
+
}
|
|
188
191
|
const isError = !_constants_1.OK_STATUSES.includes(apiResponse.status);
|
|
189
192
|
if (isError) {
|
|
190
193
|
for (const handler of context.errorHandlerChain?.reverse() || []) {
|
package/dist/sse/server.js
CHANGED
|
@@ -75,7 +75,6 @@ class SSEServer {
|
|
|
75
75
|
for (const controller of this.controllers) {
|
|
76
76
|
if (controller.sse.handlers && controller.sse.handlers[eventType]) {
|
|
77
77
|
for (const handler of controller.sse.handlers[eventType]) {
|
|
78
|
-
console.log(handler);
|
|
79
78
|
await handler.fn(event).catch(console.log);
|
|
80
79
|
}
|
|
81
80
|
}
|
package/dist/utils/controller.js
CHANGED
|
@@ -195,7 +195,7 @@ const getResponse = async (data) => {
|
|
|
195
195
|
const classOkStatus = Reflect.getMetadata(_constants_1.OK_METADATA_KEY, prototype);
|
|
196
196
|
!isError && classOkStatus && (data.response.statusCode = classOkStatus);
|
|
197
197
|
}
|
|
198
|
-
return { status: data.response.statusCode, data: appResponse };
|
|
198
|
+
return { status: data.response.statusCode, data: appResponse?.data ?? appResponse };
|
|
199
199
|
}
|
|
200
200
|
catch (err) {
|
|
201
201
|
throw err;
|
package/dist/utils/helper.d.ts
CHANGED
|
@@ -3,4 +3,4 @@ export declare function matchRoute(pattern: string, path: string): Record<string
|
|
|
3
3
|
export declare function buildRoutePattern(parts: string[]): string;
|
|
4
4
|
export declare function mergeMiddlewares(...middlewareLists: MiddlewareCB[][]): MiddlewareCB[];
|
|
5
5
|
export declare function mergeInterceptors(...interceptorLists: InterceptorCB[][]): InterceptorCB[];
|
|
6
|
-
export declare const stringifyError: (error: any) =>
|
|
6
|
+
export declare const stringifyError: (error: any) => any;
|
package/dist/utils/helper.js
CHANGED
|
@@ -62,10 +62,10 @@ function mergeInterceptors(...interceptorLists) {
|
|
|
62
62
|
}
|
|
63
63
|
const stringifyError = (error) => {
|
|
64
64
|
return JSON.stringify({
|
|
65
|
-
message: error.message,
|
|
66
|
-
stack: error.stack,
|
|
67
|
-
status: error.status,
|
|
68
|
-
code: error.code,
|
|
65
|
+
message: error?.data?.message ?? error.message,
|
|
66
|
+
stack: error?.data?.stack ?? error.stack,
|
|
67
|
+
status: error?.data?.status ?? error.status,
|
|
68
|
+
code: error?.data?.code ?? error.code,
|
|
69
69
|
}, null, 2);
|
|
70
70
|
};
|
|
71
71
|
exports.stringifyError = stringifyError;
|