@sphereon/ssi-express-support 0.17.6-unstable.8 → 0.18.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.
@@ -1 +1 @@
1
- {"version":3,"file":"express-utils.d.ts","sourceRoot":"","sources":["../src/express-utils.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,EAAE,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAC/C,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG,8CA2BtH;AAED,eAAO,MAAM,gBAAgB,QAAS,GAAG,OAAO,eAAe,OAAO,gBAAgB,QAAQ,YAAY,sDASzG,CAAA"}
1
+ {"version":3,"file":"express-utils.d.ts","sourceRoot":"","sources":["../src/express-utils.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,EAAE,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAC/C,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG,8CA+BtH;AAED,eAAO,MAAM,gBAAgB,QAAS,GAAG,OAAO,eAAe,OAAO,gBAAgB,QAAQ,YAAY,sDAYzG,CAAA"}
@@ -2,18 +2,22 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.jsonErrorHandler = exports.sendErrorResponse = void 0;
4
4
  function sendErrorResponse(response, statusCode, message, error) {
5
- if (!message) {
5
+ let msg = message;
6
+ if (!msg) {
6
7
  console.error('Message was null when calling sendErrorResponse. This should not happen');
7
- message = 'An unexpected error occurred';
8
+ msg = 'An unexpected error occurred';
8
9
  statusCode = 500;
9
10
  }
10
11
  else {
11
- console.error(`sendErrorResponse: ${typeof message === 'string' ? message : JSON.stringify(message)}`);
12
+ console.error(`sendErrorResponse: ${typeof msg === 'string' ? msg : JSON.stringify(msg)}`);
12
13
  }
13
14
  if (error) {
14
- console.error(JSON.stringify(error));
15
+ if (error instanceof Error) {
16
+ console.error(error.message);
17
+ }
18
+ console.error(`error: ${JSON.stringify(error)}`);
15
19
  }
16
- if (statusCode == 500) {
20
+ if (statusCode === 500) {
17
21
  console.error(Error().stack);
18
22
  }
19
23
  if (response.headersSent) {
@@ -21,20 +25,23 @@ function sendErrorResponse(response, statusCode, message, error) {
21
25
  return response;
22
26
  }
23
27
  response.statusCode = statusCode;
24
- if (typeof message === 'string' && !message.startsWith('{')) {
25
- message = { error: message };
28
+ if (typeof msg === 'string' && !msg.startsWith('{')) {
29
+ msg = { error: msg };
26
30
  }
27
- if (typeof message === 'string' && message.startsWith('{')) {
31
+ if (typeof msg === 'string' && msg.startsWith('{')) {
28
32
  response.header('Content-Type', 'application/json');
29
- return response.status(statusCode).end(message);
33
+ return response.status(statusCode).end(msg);
30
34
  }
31
- return response.status(statusCode).json(message);
35
+ return response.status(statusCode).json(msg);
32
36
  }
33
37
  exports.sendErrorResponse = sendErrorResponse;
34
38
  const jsonErrorHandler = (err, req, res, next) => {
35
39
  var _a;
36
40
  const statusCode = 'statusCode' in err ? err.statusCode : 500;
37
- const errorMsg = typeof err === 'string' ? err : (_a = err.message) !== null && _a !== void 0 ? _a : err;
41
+ let errorMsg = typeof err === 'string' ? err : (_a = err.message) !== null && _a !== void 0 ? _a : err;
42
+ if (typeof errorMsg !== 'string') {
43
+ errorMsg = JSON.stringify(errorMsg);
44
+ }
38
45
  if (res.headersSent) {
39
46
  console.log('Headers already sent, when calling error handler. Will defer to next error handler');
40
47
  console.log(`Error was: ${JSON.stringify(err)}`);
@@ -1 +1 @@
1
- {"version":3,"file":"express-utils.js","sourceRoot":"","sources":["../src/express-utils.ts"],"names":[],"mappings":";;;AACA,SAAgB,iBAAiB,CAAC,QAA0B,EAAE,UAAkB,EA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,GAAG,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAA,GAAG,CAAC,OAAO,mCAAI,GAAG,CAAA;IACjE,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;QAChC,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAA;KACpC;IACD,IAAI,GAAG,CAAC,WAAW,EAAE;QACnB,OAAO,CAAC,GAAG,CAAC,oFAAoF,CAAC,CAAA;QACjG,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;QAChD,OAAO,IAAI,CAAC,GAAG,CAAC,CAAA;KACjB;IACD,OAAO,iBAAiB,CAAC,GAAG,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;AAChG,CAAC,CAAA;AAZY,QAAA,gBAAgB,oBAY5B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sphereon/ssi-express-support",
3
- "version": "0.17.6-unstable.8+d7c1237c",
3
+ "version": "0.18.0",
4
4
  "source": "src/index.ts",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -76,5 +76,5 @@
76
76
  "SSI",
77
77
  "Agent"
78
78
  ],
79
- "gitHead": "d7c1237c3c384fa6fc9d775f8f165abb6a96a40a"
79
+ "gitHead": "afad00bef1e0ce6ac1637169b2e8a3b46f287255"
80
80
  }
@@ -1,16 +1,20 @@
1
1
  import express, { NextFunction } from 'express'
2
2
  export function sendErrorResponse(response: express.Response, statusCode: number, message: string | object, error?: any) {
3
- if (!message) {
3
+ let msg = message
4
+ if (!msg) {
4
5
  console.error('Message was null when calling sendErrorResponse. This should not happen')
5
- message = 'An unexpected error occurred'
6
+ msg = 'An unexpected error occurred'
6
7
  statusCode = 500
7
8
  } else {
8
- console.error(`sendErrorResponse: ${typeof message === 'string' ? message : JSON.stringify(message)}`)
9
+ console.error(`sendErrorResponse: ${typeof msg === 'string' ? msg : JSON.stringify(msg)}`)
9
10
  }
10
11
  if (error) {
11
- console.error(JSON.stringify(error))
12
+ if (error instanceof Error) {
13
+ console.error(error.message)
14
+ }
15
+ console.error(`error: ${JSON.stringify(error)}`)
12
16
  }
13
- if(statusCode == 500) {
17
+ if (statusCode === 500) {
14
18
  console.error(Error().stack)
15
19
  }
16
20
  if (response.headersSent) {
@@ -18,19 +22,22 @@ export function sendErrorResponse(response: express.Response, statusCode: number
18
22
  return response
19
23
  }
20
24
  response.statusCode = statusCode
21
- if (typeof message === 'string' && !message.startsWith('{')) {
22
- message = { error: message }
25
+ if (typeof msg === 'string' && !msg.startsWith('{')) {
26
+ msg = { error: msg }
23
27
  }
24
- if (typeof message === 'string' && message.startsWith('{')) {
28
+ if (typeof msg === 'string' && msg.startsWith('{')) {
25
29
  response.header('Content-Type', 'application/json')
26
- return response.status(statusCode).end(message)
30
+ return response.status(statusCode).end(msg)
27
31
  }
28
- return response.status(statusCode).json(message)
32
+ return response.status(statusCode).json(msg)
29
33
  }
30
34
 
31
35
  export const jsonErrorHandler = (err: any, req: express.Request, res: express.Response, next: NextFunction) => {
32
36
  const statusCode: number = 'statusCode' in err ? err.statusCode : 500
33
- const errorMsg = typeof err === 'string' ? err : err.message ?? err
37
+ let errorMsg = typeof err === 'string' ? err : err.message ?? err
38
+ if (typeof errorMsg !== 'string') {
39
+ errorMsg = JSON.stringify(errorMsg)
40
+ }
34
41
  if (res.headersSent) {
35
42
  console.log('Headers already sent, when calling error handler. Will defer to next error handler')
36
43
  console.log(`Error was: ${JSON.stringify(err)}`)