@futdevpro/nts-dynamo 1.6.53 → 1.6.54
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/lib/_models/control-models/endpoint-params.control-model.d.ts.map +1 -1
- package/lib/_models/control-models/endpoint-params.control-model.js +35 -27
- package/lib/_models/control-models/endpoint-params.control-model.js.map +1 -1
- package/lib/_services/base/db.service.d.ts.map +1 -1
- package/lib/_services/base/db.service.js +2 -9
- package/lib/_services/base/db.service.js.map +1 -1
- package/lib/_services/core/global.service.d.ts +4 -0
- package/lib/_services/core/global.service.d.ts.map +1 -1
- package/lib/_services/core/global.service.js +4 -0
- package/lib/_services/core/global.service.js.map +1 -1
- package/lib/_services/server/app.server.d.ts +5 -0
- package/lib/_services/server/app.server.d.ts.map +1 -1
- package/lib/_services/server/app.server.js +3 -2
- package/lib/_services/server/app.server.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/_models/control-models/endpoint-params.control-model.ts +14 -6
- package/src/_services/base/db.service.ts +2 -9
- package/src/_services/core/global.service.ts +9 -0
- package/src/_services/server/app.server.ts +9 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { Request, Response } from 'express';
|
|
4
4
|
|
|
5
5
|
import { Dynamo_Array, Dynamo_Error, Dynamo_Log } from '@futdevpro/fsm-dynamo';
|
|
6
6
|
import { DynamoNTS_RouteSecurity } from '../../_enums/route-security.enum';
|
|
@@ -134,7 +134,7 @@ export class DynamoNTS_EndpointParams{
|
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
} catch (error) {
|
|
137
|
-
this.error(req, res, error);
|
|
137
|
+
this.error(req, res, error, issuer);
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
|
|
@@ -143,9 +143,11 @@ export class DynamoNTS_EndpointParams{
|
|
|
143
143
|
* @returns
|
|
144
144
|
*/
|
|
145
145
|
getFullExecution(): (req: Request, res: Response) => Promise<void> {
|
|
146
|
+
let issuer: string;
|
|
147
|
+
|
|
146
148
|
return async (req: Request, res: Response) => {
|
|
147
149
|
try {
|
|
148
|
-
|
|
150
|
+
issuer = DynamoNTS_GlobalService?.getAuthService()?.getIssuerFromRequest(req);
|
|
149
151
|
|
|
150
152
|
if (this.logRequest) {
|
|
151
153
|
await this.preLog(req, res, issuer);
|
|
@@ -172,7 +174,7 @@ export class DynamoNTS_EndpointParams{
|
|
|
172
174
|
}
|
|
173
175
|
}
|
|
174
176
|
} catch (error) {
|
|
175
|
-
this.error(req, res, error);
|
|
177
|
+
this.error(req, res, error, issuer);
|
|
176
178
|
}
|
|
177
179
|
};
|
|
178
180
|
}
|
|
@@ -182,7 +184,7 @@ export class DynamoNTS_EndpointParams{
|
|
|
182
184
|
* @param res
|
|
183
185
|
* @param error
|
|
184
186
|
*/
|
|
185
|
-
private error(req: Request, res: Response, error: Error | Dynamo_Error): void {
|
|
187
|
+
private async error(req: Request, res: Response, error: Error | Dynamo_Error, issuer: string): Promise<void> {
|
|
186
188
|
try {
|
|
187
189
|
let msg: string = `Endpoint catched an error. ${this.name} (${this.endpoint})`;
|
|
188
190
|
msg += this.getPathParamsLogContent(req);
|
|
@@ -196,6 +198,11 @@ export class DynamoNTS_EndpointParams{
|
|
|
196
198
|
'\n'
|
|
197
199
|
);
|
|
198
200
|
|
|
201
|
+
await DynamoNTS_GlobalService.globalErrorHandler?.(error, req, res, issuer).catch(err => {
|
|
202
|
+
Dynamo_Log.warn('DynamoNTS_GlobalService.globalErrorHandler failed to handle error: ', err);
|
|
203
|
+
Dynamo_Log.warn('It will proceed as normal.');
|
|
204
|
+
});
|
|
205
|
+
|
|
199
206
|
res.status((error as Dynamo_Error)?.___status ?? 501);
|
|
200
207
|
res.send(error);
|
|
201
208
|
|
|
@@ -215,7 +222,8 @@ export class DynamoNTS_EndpointParams{
|
|
|
215
222
|
}
|
|
216
223
|
} catch (error) {
|
|
217
224
|
console.error(
|
|
218
|
-
|
|
225
|
+
`\n\nDYNAMO MULTILEVEL ERROR:DynamoNTS_EndpointParams:error: (${this.name}, ${this.endpoint})` +
|
|
226
|
+
`\n(DYNAMO MULTILEVEL ERROR means, that the ERRORHANDLING is ALSO FAILED, and the error message was not sent.)` +
|
|
219
227
|
`\nERROR:`, error, '\n'
|
|
220
228
|
);
|
|
221
229
|
}
|
|
@@ -100,14 +100,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
100
100
|
}
|
|
101
101
|
});
|
|
102
102
|
|
|
103
|
-
|
|
104
|
-
newData._id = `${newData._id}`;
|
|
105
|
-
if (typeof data._id !== 'string' || typeof data._id === 'object') {
|
|
106
|
-
Dynamo_Log.error('data._id stringifying failed! Please notfiy the developer! (DynamoNTS_DBService.createData)')
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
data._id = newData._id;
|
|
110
|
-
data.__v = newData.__v;
|
|
103
|
+
data = this.stringifyDataId(data, 'createData');
|
|
111
104
|
|
|
112
105
|
return data;
|
|
113
106
|
}
|
|
@@ -830,7 +823,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
830
823
|
data = JSON.parse(JSON.stringify(data));
|
|
831
824
|
|
|
832
825
|
if (typeof data._id !== 'string' || typeof data._id === 'object') {
|
|
833
|
-
Dynamo_Log.error(`data._id stringifying failed! Please notfiy the developers! (${fnName})`, new Error());
|
|
826
|
+
Dynamo_Log.error(`data._id stringifying failed! Please notfiy the DynamoNTS developers! (${fnName})`, new Error());
|
|
834
827
|
}
|
|
835
828
|
}
|
|
836
829
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
+
import { Request, Response } from 'express';
|
|
4
|
+
|
|
3
5
|
import { Dynamo_Metadata, Dynamo_DataParams, Dynamo_Log, Dynamo_Error } from '@futdevpro/fsm-dynamo';
|
|
4
6
|
import { DynamoNTS_AppParams } from '../../_models/control-models/app-params.control-model';
|
|
5
7
|
|
|
@@ -34,6 +36,9 @@ export class DynamoNTS_GlobalService extends DynamoNTS_SingletonService {
|
|
|
34
36
|
authService: DynamoNTS_AuthService;
|
|
35
37
|
dbServiceCollection: DynamoNTS_ServiceCollection<DynamoNTS_DBService<any>>; // DynamoNTS_DBServiceCollection;
|
|
36
38
|
emailServiceCollection: DynamoNTS_ServiceCollection<DynamoNTS_EmailService>; // DynamoNTS_EmailServiceCollection;
|
|
39
|
+
|
|
40
|
+
private static _globalErrorHandler?: (err: any, req: Request, res: Response, issuer: string) => Promise<void>;
|
|
41
|
+
static get globalErrorHandler(): (err: any, req: Request, res: Response, issuer: string) => Promise<void> { return this._globalErrorHandler; }
|
|
37
42
|
|
|
38
43
|
/**
|
|
39
44
|
* You need to setup global Services through this function
|
|
@@ -73,6 +78,10 @@ export class DynamoNTS_GlobalService extends DynamoNTS_SingletonService {
|
|
|
73
78
|
this._params = params;
|
|
74
79
|
}
|
|
75
80
|
|
|
81
|
+
static setGlobalErrorHandler(handler?: (err: any, req: Request, res: Response, issuer: string) => Promise<void>): void {
|
|
82
|
+
this.instance.globalErrorHandler = handler;
|
|
83
|
+
}
|
|
84
|
+
|
|
76
85
|
/**
|
|
77
86
|
*
|
|
78
87
|
* @returns
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
|
|
2
2
|
import Mongoose = require("mongoose");
|
|
3
3
|
import Express = require("express");
|
|
4
|
+
|
|
4
5
|
import * as Http from 'http';
|
|
5
6
|
import * as Https from 'https';
|
|
6
7
|
import * as FileSystem from 'fs';
|
|
7
8
|
import * as BodyParser from 'body-parser';
|
|
8
9
|
|
|
10
|
+
import { Request, Response } from 'express';
|
|
11
|
+
|
|
9
12
|
import { Dynamo_Array, Dynamo_Error, dynamo_error_default, Dynamo_Log, second, wait } from '@futdevpro/fsm-dynamo';
|
|
10
13
|
|
|
11
14
|
import { DynamoNTS_SingletonService } from '../base/singleton.service';
|
|
@@ -241,6 +244,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
241
244
|
this.globalService = DynamoNTS_GlobalService.getInstance();
|
|
242
245
|
DynamoNTS_GlobalService.setServices(this.getGlobalServiceCollection());
|
|
243
246
|
DynamoNTS_GlobalService.setParams(this.params);
|
|
247
|
+
DynamoNTS_GlobalService.setGlobalErrorHandler(this.getGlobalErrorHandler?.());
|
|
244
248
|
|
|
245
249
|
if (this.getPortSettings) {
|
|
246
250
|
this._ports = this.getPortSettings();
|
|
@@ -878,4 +882,9 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
878
882
|
* MISSING Description (TODO)
|
|
879
883
|
*/
|
|
880
884
|
postProcess?(): Promise<void>;
|
|
885
|
+
|
|
886
|
+
/**
|
|
887
|
+
* MISSING Description (TODO)
|
|
888
|
+
*/
|
|
889
|
+
getGlobalErrorHandler?(): (err: any, req: Request, res: Response, issuer: string) => Promise<void>;
|
|
881
890
|
}
|