Skip to content
This repository has been archived by the owner on Nov 11, 2023. It is now read-only.

Commit

Permalink
response -> rawResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
Tejas Kumar committed Aug 8, 2018
1 parent 4841466 commit e42627d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
13 changes: 6 additions & 7 deletions src/Get.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,20 +170,19 @@ class ContextlessGet<TData, TError> extends React.Component<
}

const request = new Request(`${base}${requestPath || path || ""}`, this.getRequestOptions(thisRequestOptions));
const response = await fetch(request);
const rawResponse = await fetch(request);
const response = await processResponse(rawResponse);

const data = await processResponse(response);

if (!response.ok) {
if (!rawResponse.ok) {
this.setState({
loading: false,
error: { message: `Failed to fetch: ${response.status} ${response.statusText}`, data },
error: { message: `Failed to fetch: ${rawResponse.status} ${rawResponse.statusText}`, data: response },
});
return null;
}

this.setState({ loading: false, data: resolve!(data) });
return data;
this.setState({ loading: false, data: resolve!(response) });
return response;
};

public render() {
Expand Down
18 changes: 9 additions & 9 deletions src/Poll.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,22 +206,22 @@ class ContextlessPoll<TData, TError> extends React.Component<
...requestOptions.headers,
},
});
const response = await fetch(request);

const responseBody = await processResponse(response);
const rawResponse = await fetch(request);
const response = await processResponse(rawResponse);

if (!this.isResponseOk(response)) {
const error = { message: `${response.status} ${response.statusText}`, data: responseBody };
this.setState({ loading: false, lastResponse: response, data: responseBody, error });
if (!this.isResponseOk(rawResponse)) {
const error = { message: `${rawResponse.status} ${rawResponse.statusText}`, data: response };
this.setState({ loading: false, lastResponse: rawResponse, data: response, error });
throw new Error(`Failed to Poll: ${error}`);
}

if (this.isModified(response, responseBody)) {
if (this.isModified(rawResponse, response)) {
this.setState(() => ({
loading: false,
lastResponse: response,
data: resolve ? resolve(responseBody) : responseBody,
lastPollIndex: response.headers.get("x-polling-index") || undefined,
lastResponse: rawResponse,
data: resolve ? resolve(response) : response,
lastPollIndex: rawResponse.headers.get("x-polling-index") || undefined,
}));
}

Expand Down

0 comments on commit e42627d

Please # to comment.