@wooksjs/event-http 0.4.34 → 0.4.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.
- package/dist/index.cjs +13 -8
- package/dist/index.d.ts +2 -0
- package/dist/index.mjs +13 -8
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -579,7 +579,7 @@ class HttpErrorRenderer extends BaseHttpResponseRenderer {
|
|
|
579
579
|
`<head><title>${data.statusCode} ${httpStatusCodes[data.statusCode]}</title></head>` +
|
|
580
580
|
`<body><center><h1>${data.statusCode} ${httpStatusCodes[data.statusCode]}</h1></center>` +
|
|
581
581
|
`<center><h4>${data.message}</h1></center><hr color="#666">` +
|
|
582
|
-
`<center style="color: #666;"> Wooks v${"0.4.
|
|
582
|
+
`<center style="color: #666;"> Wooks v${"0.4.36"} </center>` +
|
|
583
583
|
`${keys.length > 0
|
|
584
584
|
? `<pre style="${preStyles}">${JSON.stringify({
|
|
585
585
|
...data,
|
|
@@ -950,7 +950,7 @@ class WooksHttp extends wooks.WooksAdapterBase {
|
|
|
950
950
|
}
|
|
951
951
|
getServerCb() {
|
|
952
952
|
return async (req, res) => {
|
|
953
|
-
const { restoreCtx,
|
|
953
|
+
const { restoreCtx, endEvent } = createHttpContext({ req, res }, this.mergeEventOptions(this.opts?.eventOptions));
|
|
954
954
|
const { handlers } = this.wooks.lookup(req.method, req.url);
|
|
955
955
|
if (handlers || this.opts?.onNotFound) {
|
|
956
956
|
try {
|
|
@@ -960,18 +960,18 @@ class WooksHttp extends wooks.WooksAdapterBase {
|
|
|
960
960
|
this.logger.error('Internal error, please report', error);
|
|
961
961
|
restoreCtx();
|
|
962
962
|
this.respond(error);
|
|
963
|
-
|
|
963
|
+
endEvent(error.message);
|
|
964
964
|
}
|
|
965
965
|
}
|
|
966
966
|
else {
|
|
967
967
|
this.logger.debug(`404 Not found (${req.method})${req.url}`);
|
|
968
968
|
this.respond(new HttpError(404));
|
|
969
|
-
|
|
969
|
+
endEvent('Request handler not registered');
|
|
970
970
|
}
|
|
971
971
|
};
|
|
972
972
|
}
|
|
973
973
|
async processHandlers(handlers) {
|
|
974
|
-
const { restoreCtx, clearCtx, store } = useHttpContext();
|
|
974
|
+
const { restoreCtx, endEvent, clearCtx, store } = useHttpContext();
|
|
975
975
|
for (const [i, handler] of handlers.entries()) {
|
|
976
976
|
const isLastHandler = handlers.length === i + 1;
|
|
977
977
|
try {
|
|
@@ -981,15 +981,20 @@ class WooksHttp extends wooks.WooksAdapterBase {
|
|
|
981
981
|
const result = await promise;
|
|
982
982
|
restoreCtx();
|
|
983
983
|
this.respond(result);
|
|
984
|
-
|
|
984
|
+
endEvent();
|
|
985
985
|
break;
|
|
986
986
|
}
|
|
987
987
|
catch (error) {
|
|
988
|
-
|
|
988
|
+
if (error instanceof HttpError) {
|
|
989
|
+
this.logger.debug(`${error.body.statusCode}: ${error.message} :: ${store('event').get('req')?.url || ''}`);
|
|
990
|
+
}
|
|
991
|
+
else {
|
|
992
|
+
this.logger.error(`Uncought route handler exception: ${store('event').get('req')?.url || ''}`, error);
|
|
993
|
+
}
|
|
989
994
|
if (isLastHandler) {
|
|
990
995
|
restoreCtx();
|
|
991
996
|
this.respond(error);
|
|
992
|
-
|
|
997
|
+
endEvent(error.message);
|
|
993
998
|
}
|
|
994
999
|
}
|
|
995
1000
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -383,6 +383,7 @@ declare function createHttpContext(data: THttpEventData, options: TEventOptions)
|
|
|
383
383
|
getCtx: () => THttpContextStore & _wooksjs_event_core.TGenericContextStore<THttpEventData>;
|
|
384
384
|
restoreCtx: () => _wooksjs_event_core.TGenericContextStore<TEmpty>;
|
|
385
385
|
clearCtx: () => null;
|
|
386
|
+
endEvent: (abortReason?: string | undefined) => void;
|
|
386
387
|
store: <K extends keyof THttpContextStore | keyof _wooksjs_event_core.TGenericContextStore<THttpEventData>>(key: K) => {
|
|
387
388
|
value: (THttpContextStore & _wooksjs_event_core.TGenericContextStore<THttpEventData>)[K];
|
|
388
389
|
hook: <K2 extends keyof Required<THttpContextStore & _wooksjs_event_core.TGenericContextStore<THttpEventData>>[K]>(key2: K2) => {
|
|
@@ -410,6 +411,7 @@ declare function useHttpContext<T extends TEmpty>(): {
|
|
|
410
411
|
getCtx: () => THttpContextStore & T & _wooksjs_event_core.TGenericContextStore<THttpEventData>;
|
|
411
412
|
restoreCtx: () => _wooksjs_event_core.TGenericContextStore<TEmpty>;
|
|
412
413
|
clearCtx: () => null;
|
|
414
|
+
endEvent: (abortReason?: string | undefined) => void;
|
|
413
415
|
store: <K extends keyof THttpContextStore | keyof _wooksjs_event_core.TGenericContextStore<THttpEventData> | keyof T>(key: K) => {
|
|
414
416
|
value: (THttpContextStore & T & _wooksjs_event_core.TGenericContextStore<THttpEventData>)[K];
|
|
415
417
|
hook: <K2 extends keyof Required<THttpContextStore & T & _wooksjs_event_core.TGenericContextStore<THttpEventData>>[K]>(key2: K2) => {
|
package/dist/index.mjs
CHANGED
|
@@ -577,7 +577,7 @@ class HttpErrorRenderer extends BaseHttpResponseRenderer {
|
|
|
577
577
|
`<head><title>${data.statusCode} ${httpStatusCodes[data.statusCode]}</title></head>` +
|
|
578
578
|
`<body><center><h1>${data.statusCode} ${httpStatusCodes[data.statusCode]}</h1></center>` +
|
|
579
579
|
`<center><h4>${data.message}</h1></center><hr color="#666">` +
|
|
580
|
-
`<center style="color: #666;"> Wooks v${"0.4.
|
|
580
|
+
`<center style="color: #666;"> Wooks v${"0.4.36"} </center>` +
|
|
581
581
|
`${keys.length > 0
|
|
582
582
|
? `<pre style="${preStyles}">${JSON.stringify({
|
|
583
583
|
...data,
|
|
@@ -948,7 +948,7 @@ class WooksHttp extends WooksAdapterBase {
|
|
|
948
948
|
}
|
|
949
949
|
getServerCb() {
|
|
950
950
|
return async (req, res) => {
|
|
951
|
-
const { restoreCtx,
|
|
951
|
+
const { restoreCtx, endEvent } = createHttpContext({ req, res }, this.mergeEventOptions(this.opts?.eventOptions));
|
|
952
952
|
const { handlers } = this.wooks.lookup(req.method, req.url);
|
|
953
953
|
if (handlers || this.opts?.onNotFound) {
|
|
954
954
|
try {
|
|
@@ -958,18 +958,18 @@ class WooksHttp extends WooksAdapterBase {
|
|
|
958
958
|
this.logger.error('Internal error, please report', error);
|
|
959
959
|
restoreCtx();
|
|
960
960
|
this.respond(error);
|
|
961
|
-
|
|
961
|
+
endEvent(error.message);
|
|
962
962
|
}
|
|
963
963
|
}
|
|
964
964
|
else {
|
|
965
965
|
this.logger.debug(`404 Not found (${req.method})${req.url}`);
|
|
966
966
|
this.respond(new HttpError(404));
|
|
967
|
-
|
|
967
|
+
endEvent('Request handler not registered');
|
|
968
968
|
}
|
|
969
969
|
};
|
|
970
970
|
}
|
|
971
971
|
async processHandlers(handlers) {
|
|
972
|
-
const { restoreCtx, clearCtx, store } = useHttpContext();
|
|
972
|
+
const { restoreCtx, endEvent, clearCtx, store } = useHttpContext();
|
|
973
973
|
for (const [i, handler] of handlers.entries()) {
|
|
974
974
|
const isLastHandler = handlers.length === i + 1;
|
|
975
975
|
try {
|
|
@@ -979,15 +979,20 @@ class WooksHttp extends WooksAdapterBase {
|
|
|
979
979
|
const result = await promise;
|
|
980
980
|
restoreCtx();
|
|
981
981
|
this.respond(result);
|
|
982
|
-
|
|
982
|
+
endEvent();
|
|
983
983
|
break;
|
|
984
984
|
}
|
|
985
985
|
catch (error) {
|
|
986
|
-
|
|
986
|
+
if (error instanceof HttpError) {
|
|
987
|
+
this.logger.debug(`${error.body.statusCode}: ${error.message} :: ${store('event').get('req')?.url || ''}`);
|
|
988
|
+
}
|
|
989
|
+
else {
|
|
990
|
+
this.logger.error(`Uncought route handler exception: ${store('event').get('req')?.url || ''}`, error);
|
|
991
|
+
}
|
|
987
992
|
if (isLastHandler) {
|
|
988
993
|
restoreCtx();
|
|
989
994
|
this.respond(error);
|
|
990
|
-
|
|
995
|
+
endEvent(error.message);
|
|
991
996
|
}
|
|
992
997
|
}
|
|
993
998
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wooksjs/event-http",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.36",
|
|
4
4
|
"description": "@wooksjs/event-http",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
"url": "https://github.com/wooksjs/wooksjs/issues"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"wooks": "0.4.
|
|
42
|
+
"wooks": "0.4.36",
|
|
43
43
|
"@prostojs/router": "^0.2.1",
|
|
44
|
-
"@wooksjs/event-core": "0.4.
|
|
44
|
+
"@wooksjs/event-core": "0.4.36"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@prostojs/logger": "^0.4.0"
|