@belmonddev/catch-request-express-middleware 1.2.2 → 1.2.3

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.
Files changed (2) hide show
  1. package/index.js +9 -3
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -98,13 +98,19 @@ const overrideHttpModule = (httpModule, requestSentCb) => {
98
98
  };
99
99
 
100
100
  const callResponseCb = (responseCb, res) => {
101
+ let body;
102
+ try {
103
+ body = /application\/json;?.*?$/.test(res.getHeaders()['content-type'])
104
+ ? JSON.parse(res.bodyWritten)
105
+ : res.bodyWritten;
106
+ } catch (e) {
107
+ body = res.bodyWritten;
108
+ }
101
109
  responseCb({
102
110
  headers: res.getHeaders(),
103
111
  statusCode: res.statusCode,
104
112
  statusMessage: res.statusMessage,
105
- body: /application\/json;?.*?$/.test(res.getHeaders()['content-type'])
106
- ? JSON.parse(res.bodyWritten)
107
- : res.bodyWritten,
113
+ body,
108
114
  });
109
115
  };
110
116
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@belmonddev/catch-request-express-middleware",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "start": "nodemon -L --experimental-specifier-resolution=node ./src/index.js"