@crowdin/app-project-module 0.26.3 → 0.26.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.
- package/README.md +10 -0
- package/out/index.js +15 -0
- package/out/models/index.d.ts +4 -0
- package/out/util/index.d.ts +2 -1
- package/out/util/index.js +11 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -844,6 +844,16 @@ configuration.jwtValidationOptions = {
|
|
|
844
844
|
configuration.authenticationType = 'authorization_code'; //default is "crowdin_app"
|
|
845
845
|
```
|
|
846
846
|
|
|
847
|
+
### Disable global error handling
|
|
848
|
+
|
|
849
|
+
This module will handle all `unhandledRejection` and `uncaughtException` errors, log them and not kill the Node process.
|
|
850
|
+
Usually this means that code was not properly designed and contains unsafe places. And not always this built in behaviour will be suitable.
|
|
851
|
+
Therefore you can disable it:
|
|
852
|
+
|
|
853
|
+
```js
|
|
854
|
+
configuration.disableGlobalErrorHandling = true;
|
|
855
|
+
```
|
|
856
|
+
|
|
847
857
|
## Contributing
|
|
848
858
|
|
|
849
859
|
If you want to contribute please read the [Contributing](/CONTRIBUTING.md) guidelines.
|
package/out/index.js
CHANGED
|
@@ -63,12 +63,16 @@ const integration_credentials_1 = __importDefault(require("./middlewares/integra
|
|
|
63
63
|
const json_response_1 = __importDefault(require("./middlewares/json-response"));
|
|
64
64
|
const ui_module_1 = __importDefault(require("./middlewares/ui-module"));
|
|
65
65
|
const storage = __importStar(require("./storage"));
|
|
66
|
+
const util_1 = require("./util");
|
|
66
67
|
const connection_1 = require("./util/connection");
|
|
67
68
|
const cron_1 = require("./util/cron");
|
|
68
69
|
const defaults_1 = require("./util/defaults");
|
|
69
70
|
var models_1 = require("./models");
|
|
70
71
|
Object.defineProperty(exports, "Scope", { enumerable: true, get: function () { return models_1.Scope; } });
|
|
71
72
|
function addCrowdinEndpoints(app, plainConfig) {
|
|
73
|
+
if (!plainConfig.disableGlobalErrorHandling) {
|
|
74
|
+
handleUncaughtErrors(plainConfig);
|
|
75
|
+
}
|
|
72
76
|
const config = Object.assign(Object.assign({}, plainConfig), { baseUrl: plainConfig.baseUrl.endsWith('/') ? plainConfig.baseUrl.slice(0, -1) : plainConfig.baseUrl });
|
|
73
77
|
storage.initialize(config);
|
|
74
78
|
app.use(express_1.default.json({ limit: '50mb' }));
|
|
@@ -196,3 +200,14 @@ function createApp(config) {
|
|
|
196
200
|
app.listen(config.port || 3000, () => console.log(`App started on port ${config.port || 3000}`));
|
|
197
201
|
}
|
|
198
202
|
exports.createApp = createApp;
|
|
203
|
+
function handleUncaughtErrors(config) {
|
|
204
|
+
process
|
|
205
|
+
.on('unhandledRejection', (reason) => {
|
|
206
|
+
const error = `Unhandled Rejection. Reason: ${reason.stack || reason}`;
|
|
207
|
+
(0, util_1.logError)(error, config.onError);
|
|
208
|
+
})
|
|
209
|
+
.on('uncaughtException', (reason) => {
|
|
210
|
+
const error = `Uncaught Exception. Reason: ${reason.stack || reason}`;
|
|
211
|
+
(0, util_1.logError)(error, config.onError);
|
|
212
|
+
});
|
|
213
|
+
}
|
package/out/models/index.d.ts
CHANGED
|
@@ -115,6 +115,10 @@ export interface Config extends ImagePath {
|
|
|
115
115
|
* Error interceptor (can be used to log error in centralized place)
|
|
116
116
|
*/
|
|
117
117
|
onError?: (error: any) => void;
|
|
118
|
+
/**
|
|
119
|
+
* Disable global error handling of unhandledRejection and uncaughtException events
|
|
120
|
+
*/
|
|
121
|
+
disableGlobalErrorHandling?: boolean;
|
|
118
122
|
/**
|
|
119
123
|
* Configuration to log everything that are happening in the app
|
|
120
124
|
*/
|
package/out/util/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Request, Response } from 'express';
|
|
2
|
-
import { Config,
|
|
2
|
+
import { Config, ExtendedResult, Logger } from '../models';
|
|
3
3
|
export declare class CodeError extends Error {
|
|
4
4
|
code: number | undefined;
|
|
5
5
|
constructor(message: string, code?: number);
|
|
@@ -7,6 +7,7 @@ export declare class CodeError extends Error {
|
|
|
7
7
|
export declare function log(message: string, logger?: Logger): void;
|
|
8
8
|
export declare function getMessage(err: any): any;
|
|
9
9
|
export declare function runAsyncWrapper(callback: Function, onError?: (e: any) => void): (req: Request, res: Response, next: Function) => void;
|
|
10
|
+
export declare function logError(e: any, onError?: (e: any) => void): void;
|
|
10
11
|
export declare function encryptData(config: Config, data: string): string;
|
|
11
12
|
export declare function decryptData(config: Config, data: string): string;
|
|
12
13
|
export declare function executeWithRetry<T>(func: () => Promise<T>, numOfRetries?: number): Promise<T>;
|
package/out/util/index.js
CHANGED
|
@@ -28,7 +28,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
28
28
|
});
|
|
29
29
|
};
|
|
30
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
-
exports.isExtendedResultType = exports.executeWithRetry = exports.decryptData = exports.encryptData = exports.runAsyncWrapper = exports.getMessage = exports.log = exports.CodeError = void 0;
|
|
31
|
+
exports.isExtendedResultType = exports.executeWithRetry = exports.decryptData = exports.encryptData = exports.logError = exports.runAsyncWrapper = exports.getMessage = exports.log = exports.CodeError = void 0;
|
|
32
32
|
const crypto = __importStar(require("crypto-js"));
|
|
33
33
|
const storage_1 = require("../storage");
|
|
34
34
|
class CodeError extends Error {
|
|
@@ -84,17 +84,21 @@ function handleError(err, req, res) {
|
|
|
84
84
|
function runAsyncWrapper(callback, onError) {
|
|
85
85
|
return (req, res, next) => {
|
|
86
86
|
callback(req, res, next).catch((e) => {
|
|
87
|
-
|
|
88
|
-
onError(e);
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
console.error(e);
|
|
92
|
-
}
|
|
87
|
+
logError(e, onError);
|
|
93
88
|
handleError(e, req, res);
|
|
94
89
|
});
|
|
95
90
|
};
|
|
96
91
|
}
|
|
97
92
|
exports.runAsyncWrapper = runAsyncWrapper;
|
|
93
|
+
function logError(e, onError) {
|
|
94
|
+
if (onError) {
|
|
95
|
+
onError(e);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
console.error(e);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.logError = logError;
|
|
98
102
|
function encryptData(config, data) {
|
|
99
103
|
return crypto.AES.encrypt(data, config.cryptoSecret || config.clientSecret).toString();
|
|
100
104
|
}
|
package/package.json
CHANGED