@flink-app/flink 0.5.0 → 0.6.0

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/cli/run.ts CHANGED
@@ -40,7 +40,11 @@ module.exports = async function run(args: string[]) {
40
40
  console.warn("WARNING: --entry is ignored when using --precompiled");
41
41
  }
42
42
 
43
- require("child_process").fork(dir + "/dist/.flink/start.js");
43
+ const forkedProcess = require("child_process").fork(dir + "/dist/.flink/start.js");
44
+
45
+ forkedProcess.on("exit", (code: any) => {
46
+ process.exit(code);
47
+ });
44
48
  return;
45
49
  }
46
50
 
@@ -58,5 +62,9 @@ module.exports = async function run(args: string[]) {
58
62
 
59
63
  compiler.emit();
60
64
 
61
- require("child_process").fork(dir + "/dist/.flink/start.js");
65
+ const forkedProcess = require("child_process").fork(dir + "/dist/.flink/start.js");
66
+
67
+ forkedProcess.on("exit", (code: any) => {
68
+ process.exit(code);
69
+ });
62
70
  };
package/dist/cli/run.js CHANGED
@@ -43,7 +43,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
43
43
  var TypeScriptCompiler_1 = __importDefault(require("../src/TypeScriptCompiler"));
44
44
  module.exports = function run(args) {
45
45
  return __awaiter(this, void 0, void 0, function () {
46
- var startTime, dir, entry, compiler;
46
+ var startTime, dir, entry, forkedProcess_1, compiler, forkedProcess;
47
47
  return __generator(this, function (_a) {
48
48
  switch (_a.label) {
49
49
  case 0:
@@ -65,7 +65,10 @@ module.exports = function run(args) {
65
65
  if (args.includes("--entry")) {
66
66
  console.warn("WARNING: --entry is ignored when using --precompiled");
67
67
  }
68
- require("child_process").fork(dir + "/dist/.flink/start.js");
68
+ forkedProcess_1 = require("child_process").fork(dir + "/dist/.flink/start.js");
69
+ forkedProcess_1.on("exit", function (code) {
70
+ process.exit(code);
71
+ });
69
72
  return [2 /*return*/];
70
73
  }
71
74
  return [4 /*yield*/, TypeScriptCompiler_1.default.clean(dir)];
@@ -80,7 +83,10 @@ module.exports = function run(args) {
80
83
  _a.sent();
81
84
  console.log("Compilation done, took " + (Date.now() - startTime) + "ms");
82
85
  compiler.emit();
83
- require("child_process").fork(dir + "/dist/.flink/start.js");
86
+ forkedProcess = require("child_process").fork(dir + "/dist/.flink/start.js");
87
+ forkedProcess.on("exit", function (code) {
88
+ process.exit(code);
89
+ });
84
90
  return [2 /*return*/];
85
91
  }
86
92
  });
@@ -345,6 +345,18 @@ var FlinkApp = /** @class */ (function () {
345
345
  return [3 /*break*/, 6];
346
346
  case 5:
347
347
  err_1 = _a.sent();
348
+ // duck typing to check if it is a FlinkError
349
+ if (typeof err_1.status === "number" && err_1.status >= 400 && err_1.status < 600 && err_1.error) {
350
+ return [2 /*return*/, res.status(err_1.status).json({
351
+ status: err_1.status,
352
+ error: {
353
+ id: err_1.error.id || uuid_1.v4(),
354
+ title: err_1.error.title || "Unhandled error: " + (err_1.error.code || err_1.status),
355
+ detail: err_1.error.detail,
356
+ code: err_1.error.code,
357
+ },
358
+ })];
359
+ }
348
360
  FlinkLog_1.log.warn("Handler '" + methodAndRoute_1 + "' threw unhandled exception " + err_1);
349
361
  console.error(err_1);
350
362
  return [2 /*return*/, res.status(500).json(FlinkErrors_1.internalServerError(err_1))];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flink-app/flink",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Typescript only framework for creating REST-like APIs on top of Express and mongodb",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "main": "dist/src/index.js",
@@ -67,5 +67,5 @@
67
67
  "rimraf": "^3.0.2",
68
68
  "ts-node": "^9.1.1"
69
69
  },
70
- "gitHead": "3c877c210da19119c074c7482e97a485d2334e80"
70
+ "gitHead": "42ab7a99632d1fba08096d51800dfc0deb4b0222"
71
71
  }
package/src/FlinkApp.ts CHANGED
@@ -492,7 +492,20 @@ export class FlinkApp<C extends FlinkContext> {
492
492
  ctx: this.ctx,
493
493
  origin: routeProps.origin,
494
494
  });
495
- } catch (err) {
495
+ } catch (err: any) {
496
+ // duck typing to check if it is a FlinkError
497
+ if (typeof err.status === "number" && err.status >= 400 && err.status < 600 && err.error) {
498
+ return res.status(err.status).json({
499
+ status: err.status,
500
+ error: {
501
+ id: err.error.id || v4(),
502
+ title: err.error.title || `Unhandled error: ${err.error.code || err.status}`,
503
+ detail: err.error.detail,
504
+ code: err.error.code,
505
+ },
506
+ });
507
+ }
508
+
496
509
  log.warn(`Handler '${methodAndRoute}' threw unhandled exception ${err}`);
497
510
  console.error(err);
498
511
  return res.status(500).json(internalServerError(err as any));