@noxfly/noxus 1.1.8 → 1.1.9
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/noxus.d.mts +2 -0
- package/dist/noxus.d.ts +2 -0
- package/dist/noxus.js +16 -2
- package/dist/noxus.mjs +16 -2
- package/package.json +1 -1
- package/src/request.ts +1 -0
- package/src/router.ts +9 -1
- package/src/utils/logger.ts +9 -0
package/dist/noxus.d.mts
CHANGED
|
@@ -168,6 +168,7 @@ interface IResponse<T = any> {
|
|
|
168
168
|
status: number;
|
|
169
169
|
body?: T;
|
|
170
170
|
error?: string;
|
|
171
|
+
stack?: string;
|
|
171
172
|
}
|
|
172
173
|
|
|
173
174
|
|
|
@@ -614,6 +615,7 @@ declare namespace Logger {
|
|
|
614
615
|
* @param args The arguments to log.
|
|
615
616
|
*/
|
|
616
617
|
function error(...args: any[]): void;
|
|
618
|
+
function errorStack(...args: any[]): void;
|
|
617
619
|
/**
|
|
618
620
|
* Logs a message to the console with log level DEBUG.
|
|
619
621
|
* This function formats the message with a timestamp, process ID, and the name of the caller function or class.
|
package/dist/noxus.d.ts
CHANGED
|
@@ -168,6 +168,7 @@ interface IResponse<T = any> {
|
|
|
168
168
|
status: number;
|
|
169
169
|
body?: T;
|
|
170
170
|
error?: string;
|
|
171
|
+
stack?: string;
|
|
171
172
|
}
|
|
172
173
|
|
|
173
174
|
|
|
@@ -614,6 +615,7 @@ declare namespace Logger {
|
|
|
614
615
|
* @param args The arguments to log.
|
|
615
616
|
*/
|
|
616
617
|
function error(...args: any[]): void;
|
|
618
|
+
function errorStack(...args: any[]): void;
|
|
617
619
|
/**
|
|
618
620
|
* Logs a message to the console with log level DEBUG.
|
|
619
621
|
* This function formats the message with a timestamp, process ID, and the name of the caller function or class.
|
package/dist/noxus.js
CHANGED
|
@@ -548,6 +548,14 @@ var logLevelRank = {
|
|
|
548
548
|
}
|
|
549
549
|
__name(error, "error");
|
|
550
550
|
Logger2.error = error;
|
|
551
|
+
function errorStack(...args) {
|
|
552
|
+
if (!canLog("error")) return;
|
|
553
|
+
const callee = getCallee();
|
|
554
|
+
const prefix = getLogPrefix(callee, "error", Logger2.colors.grey);
|
|
555
|
+
console.error(prefix, ...formattedArgs(prefix, args, Logger2.colors.grey));
|
|
556
|
+
}
|
|
557
|
+
__name(errorStack, "errorStack");
|
|
558
|
+
Logger2.errorStack = errorStack;
|
|
551
559
|
function debug(...args) {
|
|
552
560
|
if (!canLog("debug")) return;
|
|
553
561
|
const callee = getCallee();
|
|
@@ -929,8 +937,7 @@ var _Router = class _Router {
|
|
|
929
937
|
const response = {
|
|
930
938
|
requestId: request.id,
|
|
931
939
|
status: 200,
|
|
932
|
-
body: null
|
|
933
|
-
error: void 0
|
|
940
|
+
body: null
|
|
934
941
|
};
|
|
935
942
|
try {
|
|
936
943
|
const routeDef = this.findRoute(request);
|
|
@@ -939,15 +946,19 @@ var _Router = class _Router {
|
|
|
939
946
|
throw new ResponseException(response.status, response.error);
|
|
940
947
|
}
|
|
941
948
|
} catch (error) {
|
|
949
|
+
response.body = void 0;
|
|
942
950
|
if (error instanceof ResponseException) {
|
|
943
951
|
response.status = error.status;
|
|
944
952
|
response.error = error.message;
|
|
953
|
+
response.stack = error.stack;
|
|
945
954
|
} else if (error instanceof Error) {
|
|
946
955
|
response.status = 500;
|
|
947
956
|
response.error = error.message || "Internal Server Error";
|
|
957
|
+
response.stack = error.stack || "No stack trace available";
|
|
948
958
|
} else {
|
|
949
959
|
response.status = 500;
|
|
950
960
|
response.error = "Unknown error occurred";
|
|
961
|
+
response.stack = "No stack trace available";
|
|
951
962
|
}
|
|
952
963
|
} finally {
|
|
953
964
|
const t1 = performance.now();
|
|
@@ -957,6 +968,9 @@ var _Router = class _Router {
|
|
|
957
968
|
else Logger.error(message);
|
|
958
969
|
if (response.error !== void 0) {
|
|
959
970
|
Logger.error(response.error);
|
|
971
|
+
if (response.stack !== void 0) {
|
|
972
|
+
Logger.errorStack(response.stack);
|
|
973
|
+
}
|
|
960
974
|
}
|
|
961
975
|
return response;
|
|
962
976
|
}
|
package/dist/noxus.mjs
CHANGED
|
@@ -471,6 +471,14 @@ var logLevelRank = {
|
|
|
471
471
|
}
|
|
472
472
|
__name(error, "error");
|
|
473
473
|
Logger2.error = error;
|
|
474
|
+
function errorStack(...args) {
|
|
475
|
+
if (!canLog("error")) return;
|
|
476
|
+
const callee = getCallee();
|
|
477
|
+
const prefix = getLogPrefix(callee, "error", Logger2.colors.grey);
|
|
478
|
+
console.error(prefix, ...formattedArgs(prefix, args, Logger2.colors.grey));
|
|
479
|
+
}
|
|
480
|
+
__name(errorStack, "errorStack");
|
|
481
|
+
Logger2.errorStack = errorStack;
|
|
474
482
|
function debug(...args) {
|
|
475
483
|
if (!canLog("debug")) return;
|
|
476
484
|
const callee = getCallee();
|
|
@@ -852,8 +860,7 @@ var _Router = class _Router {
|
|
|
852
860
|
const response = {
|
|
853
861
|
requestId: request.id,
|
|
854
862
|
status: 200,
|
|
855
|
-
body: null
|
|
856
|
-
error: void 0
|
|
863
|
+
body: null
|
|
857
864
|
};
|
|
858
865
|
try {
|
|
859
866
|
const routeDef = this.findRoute(request);
|
|
@@ -862,15 +869,19 @@ var _Router = class _Router {
|
|
|
862
869
|
throw new ResponseException(response.status, response.error);
|
|
863
870
|
}
|
|
864
871
|
} catch (error) {
|
|
872
|
+
response.body = void 0;
|
|
865
873
|
if (error instanceof ResponseException) {
|
|
866
874
|
response.status = error.status;
|
|
867
875
|
response.error = error.message;
|
|
876
|
+
response.stack = error.stack;
|
|
868
877
|
} else if (error instanceof Error) {
|
|
869
878
|
response.status = 500;
|
|
870
879
|
response.error = error.message || "Internal Server Error";
|
|
880
|
+
response.stack = error.stack || "No stack trace available";
|
|
871
881
|
} else {
|
|
872
882
|
response.status = 500;
|
|
873
883
|
response.error = "Unknown error occurred";
|
|
884
|
+
response.stack = "No stack trace available";
|
|
874
885
|
}
|
|
875
886
|
} finally {
|
|
876
887
|
const t1 = performance.now();
|
|
@@ -880,6 +891,9 @@ var _Router = class _Router {
|
|
|
880
891
|
else Logger.error(message);
|
|
881
892
|
if (response.error !== void 0) {
|
|
882
893
|
Logger.error(response.error);
|
|
894
|
+
if (response.stack !== void 0) {
|
|
895
|
+
Logger.errorStack(response.stack);
|
|
896
|
+
}
|
|
883
897
|
}
|
|
884
898
|
return response;
|
|
885
899
|
}
|
package/package.json
CHANGED
package/src/request.ts
CHANGED
package/src/router.ts
CHANGED
|
@@ -129,7 +129,6 @@ export class Router {
|
|
|
129
129
|
requestId: request.id,
|
|
130
130
|
status: 200,
|
|
131
131
|
body: null,
|
|
132
|
-
error: undefined,
|
|
133
132
|
};
|
|
134
133
|
|
|
135
134
|
try {
|
|
@@ -141,17 +140,22 @@ export class Router {
|
|
|
141
140
|
}
|
|
142
141
|
}
|
|
143
142
|
catch(error: unknown) {
|
|
143
|
+
response.body = undefined;
|
|
144
|
+
|
|
144
145
|
if(error instanceof ResponseException) {
|
|
145
146
|
response.status = error.status;
|
|
146
147
|
response.error = error.message;
|
|
148
|
+
response.stack = error.stack;
|
|
147
149
|
}
|
|
148
150
|
else if(error instanceof Error) {
|
|
149
151
|
response.status = 500;
|
|
150
152
|
response.error = error.message || 'Internal Server Error';
|
|
153
|
+
response.stack = error.stack || 'No stack trace available';
|
|
151
154
|
}
|
|
152
155
|
else {
|
|
153
156
|
response.status = 500;
|
|
154
157
|
response.error = 'Unknown error occurred';
|
|
158
|
+
response.stack = 'No stack trace available';
|
|
155
159
|
}
|
|
156
160
|
}
|
|
157
161
|
finally {
|
|
@@ -168,6 +172,10 @@ export class Router {
|
|
|
168
172
|
|
|
169
173
|
if(response.error !== undefined) {
|
|
170
174
|
Logger.error(response.error);
|
|
175
|
+
|
|
176
|
+
if(response.stack !== undefined) {
|
|
177
|
+
Logger.errorStack(response.stack);
|
|
178
|
+
}
|
|
171
179
|
}
|
|
172
180
|
|
|
173
181
|
return response;
|
package/src/utils/logger.ts
CHANGED
|
@@ -188,6 +188,15 @@ export namespace Logger {
|
|
|
188
188
|
console.error(prefix, ...formattedArgs(prefix, args, colors.red));
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
+
export function errorStack(...args: any[]): void {
|
|
192
|
+
if(!canLog('error'))
|
|
193
|
+
return;
|
|
194
|
+
|
|
195
|
+
const callee = getCallee();
|
|
196
|
+
const prefix = getLogPrefix(callee, "error", colors.grey);
|
|
197
|
+
console.error(prefix, ...formattedArgs(prefix, args, colors.grey));
|
|
198
|
+
}
|
|
199
|
+
|
|
191
200
|
/**
|
|
192
201
|
* Logs a message to the console with log level DEBUG.
|
|
193
202
|
* This function formats the message with a timestamp, process ID, and the name of the caller function or class.
|