Skip to content

Commit

Permalink
Show nice error message on network time out (#3036)
Browse files Browse the repository at this point in the history
Shows "Network error. Please refresh your page
and try again." when the retry middleware times
out from too many attempts on failed/timed out
requests.

CORL-1199

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
nick-funk and kodiakhq[bot] committed Jul 22, 2020
1 parent 7f98f13 commit fe19ffd
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/core/client/framework/components/NetworkError.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.root {
background-color: var(--palette-error-300);

font-family: var(--font-family-primary);
font-weight: var(--font-weight-primary-semi-bold);
font-size: var(--font-size-3);
line-height: var(--line-height-3);
color: var(--palette-text-500);

border-radius: var(--round-corners);

padding: var(--spacing-3);
}
16 changes: 16 additions & 0 deletions src/core/client/framework/components/NetworkError.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Localized } from "@fluent/react/compat";
import React, { FunctionComponent } from "react";

import styles from "./NetworkError.css";

const NetworkError: FunctionComponent = () => {
return (
<div className={styles.root}>
<Localized id="common-networkError">
<div>Network error. Please refresh your page and try again.</div>
</Localized>
</div>
);
};

export default NetworkError;
16 changes: 15 additions & 1 deletion src/core/client/framework/lib/relay/QueryRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { Component } from "react";
import { QueryRenderer } from "react-relay";
import { OperationType } from "relay-runtime";

import NetworkError from "coral-framework/components/NetworkError";
import { PropTypesOf } from "coral-framework/types";

import { CoralContextConsumer } from "../bootstrap/CoralContext";
Expand Down Expand Up @@ -33,7 +34,20 @@ class CoralQueryRenderer<
return (
<CoralContextConsumer>
{({ relayEnvironment }) => (
<QueryRenderer environment={relayEnvironment} {...this.props} />
<QueryRenderer
environment={relayEnvironment}
{...this.props}
render={(args) => {
if (
args.error &&
args.error.name === "RRNLRetryMiddlewareError"
) {
return <NetworkError />;
}

return this.props.render(args);
}}
/>
)}
</CoralContextConsumer>
);
Expand Down
1 change: 1 addition & 0 deletions src/locales/en-US/common.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ common-banEmailTemplate =
Someone with access to your account has violated our community guidelines. As a result, your account has been banned. You will no longer be able to comment, react or report comments.
common-embedNotFound = Requested media could not be found. May have been deleted.
common-networkError = Network error. Please refresh your page and try again.

0 comments on commit fe19ffd

Please sign in to comment.