@vario-software/vario-app-framework-backend 2025.41.0 → 2025.42.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/app.js CHANGED
@@ -12,10 +12,17 @@ const OfflineToken = require('#backend/modules/offlineToken.js');
12
12
  const AccessToken = require('#backend/modules/accessToken.js');
13
13
  const BaseUrlCache = require('#backend/modules/baseUrlCache.js');
14
14
 
15
+ let exceptionHandler;
16
+
15
17
  const VarioCloudApp = class
16
18
  {
17
19
  constructor(client, options = {})
18
20
  {
21
+ this.onUnhandledError = options.onUnhandledError ?? console.error;
22
+ this.onMigrationError = options.onMigrationError ?? console.error;
23
+
24
+ exceptionHandler = setupException(this);
25
+
19
26
  this.express = express();
20
27
  this.port = '8080';
21
28
  this.uiPath = null;
@@ -26,6 +33,7 @@ const VarioCloudApp = class
26
33
  this.client = client;
27
34
 
28
35
  this.log = options.log ?? log;
36
+
29
37
  this.offlineToken = options.offlineToken ?? new OfflineToken(this);
30
38
  this.accessToken = options.accessToken ?? new AccessToken(this);
31
39
  this.baseUrlCache = options.baseUrlCache ?? new BaseUrlCache(this);
@@ -78,7 +86,7 @@ const VarioCloudApp = class
78
86
  this.express.use(this.uiPrefix, this.uiServer);
79
87
  }
80
88
 
81
- this.express.use(setupException(this));
89
+ this.express.use(exceptionHandler);
82
90
 
83
91
  return new Promise((resolve, reject) =>
84
92
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vario-software/vario-app-framework-backend",
3
- "version": "2025.41.0",
3
+ "version": "2025.42.0",
4
4
  "repository": "https://github.com/vario-software/vario-app-framework",
5
5
  "author": "VARIO Software AG",
6
6
  "homepage": "https://www.vario.ag",
@@ -1,9 +1,57 @@
1
1
  const { getResponse, getApp } = require('#backend/utils/context.js');
2
2
  const HttpError = require('#backend/utils/httpError.js');
3
3
 
4
- function setupException()
4
+ function setupException(app)
5
5
  {
6
+ async function errorHandling(error)
7
+ {
8
+ if (error.handled)
9
+ {
10
+ return;
11
+ }
12
+
13
+ error.handled = true;
14
+
15
+ const response = getResponse();
16
+ const statusCode = error.statusCode ?? 500;
17
+ const logLevel = error.logLevel ?? 'ERROR';
18
+ const logService = error.logService ?? 'setup/exception';
19
+ const stackTrace = error.stack?.split('\n').map(line => line.trim());
20
+ const { logInfo, data } = error;
21
+
22
+ let message = 'UNKNOWN_ERROR';
23
+
24
+ if (error instanceof HttpError)
25
+ {
26
+ if (error.message)
27
+ {
28
+ message = error.message;
29
+ }
30
+
31
+ await getApp()?.log(
32
+ {
33
+ statusCode,
34
+ message,
35
+ logInfo,
36
+ stackTrace,
37
+ },
38
+ logService,
39
+ logLevel,
40
+ );
41
+ }
42
+ else
43
+ {
44
+ await app.onUnhandledError(error);
45
+ }
46
+
47
+ if (response && !response.headersSent)
48
+ {
49
+ response.status(statusCode).send({ error: message, data }).end();
50
+ }
51
+ }
52
+
6
53
  process.on('unhandledRejection', reason => errorHandling(reason));
54
+ process.on('uncaughtException', reason => errorHandling(reason));
7
55
 
8
56
  // eslint-disable-next-line no-unused-vars
9
57
  return (error, req, res, next) =>
@@ -12,38 +60,4 @@ function setupException()
12
60
  };
13
61
  }
14
62
 
15
- async function errorHandling(error)
16
- {
17
- const response = getResponse();
18
- const statusCode = error.statusCode ?? 500;
19
- const message = error.message ?? 'UNKNOWN_ERROR';
20
- const logLevel = error.logLevel ?? 'ERROR';
21
- const logService = error.logService ?? 'setup/exception';
22
- const stackTrace = error.stack?.split('\n').map(line => line.trim());
23
- const { logInfo, data } = error;
24
-
25
- if (error instanceof HttpError)
26
- {
27
- await getApp()?.log(
28
- {
29
- statusCode,
30
- message,
31
- logInfo,
32
- stackTrace,
33
- },
34
- logService,
35
- logLevel,
36
- );
37
- }
38
- else
39
- {
40
- console.warn(error);
41
- }
42
-
43
- if (response && !response.headersSent)
44
- {
45
- response.status(statusCode).send({ error: message, data }).end();
46
- }
47
- }
48
-
49
63
  module.exports = setupException;
package/utils/migrator.js CHANGED
@@ -47,6 +47,8 @@ const Migrator = class
47
47
  }
48
48
  catch (error)
49
49
  {
50
+ await this.app.onMigrationError(error);
51
+
50
52
  await this.methods.log(`Migration "${migration}" failed\n\n${error.message}`, 'ERROR', error.message);
51
53
  }
52
54
  };