http-snapshotter 0.2.0 → 0.2.1
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
|
@@ -171,11 +171,17 @@ async function saveSnapshot(request, response) {
|
|
|
171
171
|
let responseType;
|
|
172
172
|
const contentType = response.headers.get('content-type') || '';
|
|
173
173
|
if (contentType.includes('application/json') || contentType.includes('application/x-amz-json-1.0')) {
|
|
174
|
-
|
|
175
|
-
|
|
174
|
+
try {
|
|
175
|
+
// most common JSON parse failure is when body is empty.
|
|
176
|
+
body = await response.clone().json();
|
|
177
|
+
responseType = 'json';
|
|
178
|
+
} catch (err) {
|
|
179
|
+
body = await response.clone().text();
|
|
180
|
+
responseType = 'text';
|
|
181
|
+
}
|
|
176
182
|
} else {
|
|
177
|
-
responseType = 'text';
|
|
178
183
|
body = await response.clone().text();
|
|
184
|
+
responseType = 'text';
|
|
179
185
|
}
|
|
180
186
|
/** @type {Snapshot} */
|
|
181
187
|
const snapshot = {
|