@crowdin/app-project-module 0.13.1 → 0.13.2

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 CHANGED
@@ -483,6 +483,9 @@ const configuration = {
483
483
  translate: async (client, context, projectId, source, target, strings) => {
484
484
  //translate strings
485
485
  const translations = ['hello', 'world'];
486
+ if (source === 'fr') {
487
+ throw 'Source language is not supported by the model';
488
+ }
486
489
  return translations;
487
490
  }
488
491
  }
@@ -16,15 +16,23 @@ function handle(baseConfig, config) {
16
16
  const target = req.query.target;
17
17
  const body = req.body;
18
18
  const projectId = Number(req.query.project_id);
19
- if (source === 'en' && target === 'de' && body.strings && body.strings[0] === 'validation') {
20
- if (config.validate) {
21
- yield config.validate(req.crowdinApiClient);
19
+ try {
20
+ if (source === 'en' && target === 'de' && body.strings && body.strings[0] === 'validation') {
21
+ if (config.validate) {
22
+ yield config.validate(req.crowdinApiClient);
23
+ }
24
+ res.send({ data: { translations: [] } });
25
+ }
26
+ else {
27
+ const translations = yield config.translate(req.crowdinApiClient, req.crowdinContext, projectId, source, target, body.strings);
28
+ res.send({ data: { translations } });
22
29
  }
23
- res.send({ data: { translations: [] } });
24
30
  }
25
- else {
26
- const translations = yield config.translate(req.crowdinApiClient, req.crowdinContext, projectId, source, target, body.strings);
27
- res.send({ data: { translations } });
31
+ catch (e) {
32
+ const message = (0, util_1.getMessage)(e);
33
+ res.send({
34
+ error: { message },
35
+ });
28
36
  }
29
37
  }), baseConfig.onError);
30
38
  }
@@ -5,6 +5,7 @@ export declare class CodeError extends Error {
5
5
  code: number | undefined;
6
6
  constructor(message: string, code?: number);
7
7
  }
8
+ export declare function getMessage(err: any): any;
8
9
  export declare function runAsyncWrapper(callback: Function, onError?: (e: any) => void): (req: Request, res: Response, next: Function) => void;
9
10
  export declare function encryptData(secret: string, data: string): string;
10
11
  export declare function decryptData(secret: string, data: string): string;
package/out/util/index.js CHANGED
@@ -31,7 +31,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
31
31
  return (mod && mod.__esModule) ? mod : { "default": mod };
32
32
  };
33
33
  Object.defineProperty(exports, "__esModule", { value: true });
34
- exports.filesCron = exports.runJob = exports.prepareIntegrationCredentials = exports.prepareCrowdinClient = exports.applyDefaults = exports.getRootFolder = exports.getOauthRoute = exports.decryptData = exports.encryptData = exports.runAsyncWrapper = exports.CodeError = void 0;
34
+ exports.filesCron = exports.runJob = exports.prepareIntegrationCredentials = exports.prepareCrowdinClient = exports.applyDefaults = exports.getRootFolder = exports.getOauthRoute = exports.decryptData = exports.encryptData = exports.runAsyncWrapper = exports.getMessage = exports.CodeError = void 0;
35
35
  const crowdin_api_client_1 = __importDefault(require("@crowdin/crowdin-api-client"));
36
36
  const crowdinAppFunctions = __importStar(require("@crowdin/crowdin-apps-functions"));
37
37
  const axios_1 = __importDefault(require("axios"));
@@ -48,6 +48,20 @@ exports.CodeError = CodeError;
48
48
  function isCrowdinClientRequest(req) {
49
49
  return req.crowdinContext;
50
50
  }
51
+ function getMessage(err) {
52
+ let message;
53
+ if (typeof err === 'string') {
54
+ message = err;
55
+ }
56
+ else if (err.message) {
57
+ message = err.message;
58
+ }
59
+ else {
60
+ message = JSON.stringify(err);
61
+ }
62
+ return message;
63
+ }
64
+ exports.getMessage = getMessage;
51
65
  function handleError(err, req, res) {
52
66
  return __awaiter(this, void 0, void 0, function* () {
53
67
  const code = err.code ? err.code : 500;
@@ -58,17 +72,7 @@ function handleError(err, req, res) {
58
72
  res.redirect('/');
59
73
  return;
60
74
  }
61
- let message;
62
- if (typeof err === 'string') {
63
- message = err;
64
- }
65
- else if (err.message) {
66
- message = err.message;
67
- }
68
- else {
69
- message = JSON.stringify(err);
70
- }
71
- res.status(code).send({ message, code });
75
+ res.status(code).send({ message: getMessage(err), code });
72
76
  });
73
77
  }
74
78
  function runAsyncWrapper(callback, onError) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crowdin/app-project-module",
3
- "version": "0.13.1",
3
+ "version": "0.13.2",
4
4
  "description": "Module that generates for you all common endpoints for serving standalone Crowdin App",
5
5
  "main": "out/index.js",
6
6
  "types": "out/index.d.ts",