@noxfly/noxus 1.1.7 → 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 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
  }
@@ -1030,7 +1044,7 @@ var _Router = class _Router {
1030
1044
  const guardIndex = i - middlewares2.length;
1031
1045
  const guardType = routeDef.guards[guardIndex];
1032
1046
  await this.runGuard(request, guardType);
1033
- dispatch(i + 1);
1047
+ await dispatch(i + 1);
1034
1048
  return;
1035
1049
  }
1036
1050
  const action = controllerInstance[routeDef.handler];
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
  }
@@ -953,7 +967,7 @@ var _Router = class _Router {
953
967
  const guardIndex = i - middlewares2.length;
954
968
  const guardType = routeDef.guards[guardIndex];
955
969
  await this.runGuard(request, guardType);
956
- dispatch(i + 1);
970
+ await dispatch(i + 1);
957
971
  return;
958
972
  }
959
973
  const action = controllerInstance[routeDef.handler];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noxfly/noxus",
3
- "version": "1.1.7",
3
+ "version": "1.1.9",
4
4
  "main": "dist/noxus.js",
5
5
  "types": "dist/noxus.d.ts",
6
6
  "scripts": {
package/src/request.ts CHANGED
@@ -51,4 +51,5 @@ export interface IResponse<T = any> {
51
51
  status: number;
52
52
  body?: T;
53
53
  error?: string;
54
+ stack?: string;
54
55
  }
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;
@@ -257,7 +265,7 @@ export class Router {
257
265
  const guardIndex = i - middlewares.length;
258
266
  const guardType = routeDef.guards[guardIndex]!;
259
267
  await this.runGuard(request, guardType);
260
- dispatch(i + 1);
268
+ await dispatch(i + 1);
261
269
  return;
262
270
  }
263
271
 
@@ -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.