@aneuhold/core-ts-api-lib 1.0.16 → 1.0.17

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.
@@ -12,6 +12,10 @@ export default class DOFunctionService {
12
12
  /**
13
13
  * A generic method to handle any API request on the backend. This has
14
14
  * no use on the frontend.
15
+ *
16
+ * This will take care of returning the error if the handler throws.
17
+ * Ideally the handler should not throw though unless something really
18
+ * unexpected happened.
15
19
  */
16
20
  static handleApiRequest<TInput extends DOFunctionInput, TOutput extends DOFunctionOutput>(rawInput: DOFunctionRawInput, handler: (input: TInput) => Promise<DOFunctionCallOutput<TOutput>>): Promise<DOFunctionRawOutput>;
17
21
  }
@@ -1 +1 @@
1
- {"version":3,"file":"DOFunctionService.d.ts","sourceRoot":"","sources":["../../../src/services/DOFunctionService/DOFunctionService.ts"],"names":[],"mappings":"AACA,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,cAAc,CAAC;AACtB,OAAO,iBAAiB,MAAM,+BAA+B,CAAC;AAC9D,OAAO,gBAAgB,MAAM,8BAA8B,CAAC;AAC5D,OAAO,gBAAgB,MAAM,8BAA8B,CAAC;AAE5D;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,iBAAiB;IACpC,MAAM,CAAC,iBAAiB,oBAAmC;IAE3D,MAAM,CAAC,gBAAgB,mBAAkC;IAEzD,MAAM,CAAC,gBAAgB,mBAAkC;IAEzD;;;OAGG;WACU,gBAAgB,CAC3B,MAAM,SAAS,eAAe,EAC9B,OAAO,SAAS,gBAAgB,EAEhC,QAAQ,EAAE,kBAAkB,EAC5B,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC,GACjE,OAAO,CAAC,mBAAmB,CAAC;CAWhC"}
1
+ {"version":3,"file":"DOFunctionService.d.ts","sourceRoot":"","sources":["../../../src/services/DOFunctionService/DOFunctionService.ts"],"names":[],"mappings":"AACA,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,cAAc,CAAC;AACtB,OAAO,iBAAiB,MAAM,+BAA+B,CAAC;AAC9D,OAAO,gBAAgB,MAAM,8BAA8B,CAAC;AAC5D,OAAO,gBAAgB,MAAM,8BAA8B,CAAC;AAE5D;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,iBAAiB;IACpC,MAAM,CAAC,iBAAiB,oBAAmC;IAE3D,MAAM,CAAC,gBAAgB,mBAAkC;IAEzD,MAAM,CAAC,gBAAgB,mBAAkC;IAEzD;;;;;;;OAOG;WACU,gBAAgB,CAC3B,MAAM,SAAS,eAAe,EAC9B,OAAO,SAAS,gBAAgB,EAEhC,QAAQ,EAAE,kBAAkB,EAC5B,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC,GACjE,OAAO,CAAC,mBAAmB,CAAC;CAmBhC"}
@@ -17,17 +17,30 @@ class DOFunctionService {
17
17
  /**
18
18
  * A generic method to handle any API request on the backend. This has
19
19
  * no use on the frontend.
20
+ *
21
+ * This will take care of returning the error if the handler throws.
22
+ * Ideally the handler should not throw though unless something really
23
+ * unexpected happened.
20
24
  */
21
25
  static async handleApiRequest(rawInput, handler) {
22
26
  const input = bson_1.EJSON.parse(rawInput.data);
23
- const output = await handler(input);
24
- return {
27
+ const rawOutput = {
25
28
  body: {
26
- success: output.success,
27
- errors: output.errors,
28
- data: bson_1.EJSON.stringify(output.data, { relaxed: false })
29
+ success: false,
30
+ errors: [],
31
+ data: ''
29
32
  }
30
33
  };
34
+ try {
35
+ const output = await handler(input);
36
+ rawOutput.body.success = output.success;
37
+ rawOutput.body.errors = output.errors;
38
+ rawOutput.body.data = bson_1.EJSON.stringify(output.data, { relaxed: false });
39
+ }
40
+ catch (error) {
41
+ rawOutput.body.errors.push(JSON.stringify(error));
42
+ }
43
+ return rawOutput;
31
44
  }
32
45
  }
33
46
  exports.default = DOFunctionService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aneuhold/core-ts-api-lib",
3
- "version": "1.0.16",
3
+ "version": "1.0.17",
4
4
  "description": "A library for interacting with the backend and defining the backend API for personal projects.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",