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

Commit

Permalink
Finishing touches to implementing Contiamo Polling spec
Browse files Browse the repository at this point in the history
  • Loading branch information
Tejas Kumar committed Aug 1, 2018
1 parent 33a8c3c commit 02847e5
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Poll.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ class ContextlessPoll<T> extends React.Component<PollProps<T>, Readonly<PollStat
private getRequestOptions = () =>
typeof this.props.requestOptions === "function" ? this.props.requestOptions() : this.props.requestOptions || {};

// 304 is not a OK status code but is green in Chrome 🤦🏾‍♂️
private isResponseOk = (response: Response) => response.ok || response.status === 304;

/**
* This thing does the actual poll.
*/
Expand Down Expand Up @@ -203,7 +206,7 @@ class ContextlessPoll<T> extends React.Component<PollProps<T>, Readonly<PollStat
const responseBody =
response.headers.get("content-type") === "application/json" ? await response.json() : await response.text();

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

0 comments on commit 02847e5

Please sign in to comment.