Skip to content

Commit

Permalink
Improve error message on timeout requests
Browse files Browse the repository at this point in the history
  • Loading branch information
devinmatte committed Jan 30, 2024
1 parent 9402fa0 commit 59af374
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/chalicelib/s3_historical.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def headways(stop_ids, sdate, edate):
{
"route_id": this["route_id"],
"direction": this["direction_id"],
"current_dep_dt": this["event_time"],
"current_dep_dt": date_utils.return_formatted_date(this_dt),
"headway_time_sec": headway_time_sec,
"benchmark_headway_time_sec": benchmark_headway,
}
Expand Down

0 comments on commit 59af374

Please sign in to comment.