@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.
- package/index.js +9 -3
- 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
|
|
106
|
-
? JSON.parse(res.bodyWritten)
|
|
107
|
-
: res.bodyWritten,
|
|
113
|
+
body,
|
|
108
114
|
});
|
|
109
115
|
};
|
|
110
116
|
|