Skip to content

Commit 6c99fc3

Browse files
author
Ujjwal Mishra
committed
use cloned response to log
1 parent 05abf80 commit 6c99fc3

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

Diff for: dist/main.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: src/index.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,26 @@ class ApiLogger {
5858

5959
this.originalFetch.apply(window, arguments)
6060
.then((response) => {
61-
if (response && response.status >= 400) {
61+
const clonedResponse = response && response.clone();
62+
if (clonedResponse && clonedResponse.status >= 400) {
6263
body = body && this.getBody(body);
63-
const contentType = response.headers.get("content-type");
64+
const contentType = clonedResponse.headers.get("content-type");
6465
const logData = {
6566
id: new Date().getTime(),
6667
url,
6768
method,
6869
body,
69-
status: response.status,
70-
contentType: response.headers.get("content-type")
70+
status: clonedResponse.status,
71+
contentType: clonedResponse.headers.get("content-type")
7172
}
7273
if (contentType && contentType.includes("application/json")) {
73-
return response.clone().json().then((json) => {
74+
return clonedResponse.clone().json().then((json) => {
7475
logData.response = json
7576
store.push(logData);
7677
resolve(response);
7778
});
7879
} else {
79-
return response.clone().text().then((text) => {
80+
return clonedResponse.clone().text().then((text) => {
8081
logData.response = text;
8182
store.push(logData);
8283
resolve(response);

0 commit comments

Comments
 (0)