Skip to content

Commit

Permalink
Improve error message on timedout requests (#944)
Browse files Browse the repository at this point in the history
  • Loading branch information
devinmatte authored Jan 30, 2024
1 parent 5721452 commit 33c05ad
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion common/components/graphics/ChartPlaceHolder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const ChartPlaceHolder: React.FC<ChartPlaceHolder> = ({
const isError = query?.isError || readyState === 'error';
return (
<div className="relative flex h-60 w-full items-center justify-center">
{isError ? <ErrorNotice inverse={inverse} /> : <LoadingSpinner />}
{isError ? <ErrorNotice query={query} inverse={inverse} /> : <LoadingSpinner />}
</div>
);
};
16 changes: 14 additions & 2 deletions common/components/notices/ErrorNotice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@ import { faTriangleExclamation } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import classNames from 'classnames';
import React from 'react';
import type { UseQueryResult } from '@tanstack/react-query';
import { useDelimitatedRoute } from '../../utils/router';
import { mbtaTextConfig } from '../../styles/general';

interface ErrorNoticeProps {
query?: UseQueryResult<unknown>;
isWidget?: boolean;
inverse?: boolean;
}

export const ErrorNotice: React.FC<ErrorNoticeProps> = ({ isWidget, inverse }) => {
export const ErrorNotice: React.FC<ErrorNoticeProps> = ({ isWidget, inverse, query }) => {
const { line } = useDelimitatedRoute();

const errorMessage = query?.error?.['message'];
const timeout = errorMessage === 'network request failed';

const color = !inverse && line ? mbtaTextConfig[line] : undefined;
return (
<div
Expand All @@ -22,7 +27,14 @@ export const ErrorNotice: React.FC<ErrorNoticeProps> = ({ isWidget, inverse }) =
)}
>
<FontAwesomeIcon size={'3x'} icon={faTriangleExclamation} className={color} />
<>An error has occurred</>
{timeout ? (
<>
<p>The response took too long</p>
<p>Try shrinking the date range and try again</p>
</>
) : (
<p>An error has occurred</p>
)}
</div>
);
};
2 changes: 1 addition & 1 deletion server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def healthcheck():
checks = {
"API Key Present": (lambda: len(secrets.MBTA_V2_API_KEY) > 0),
"S3 Headway Fetching": (
lambda: "2020-11-07 10:33:40"
lambda: "2020-11-07T10:33:40"
in json.dumps(data_funcs.headways(date(year=2020, month=11, day=7), ["70061"]))
),
"Performance API Check": (
Expand Down

0 comments on commit 33c05ad

Please sign in to comment.