| @@ -1,10 +1,18 @@ | ||
| 1 | 1 | import { __ } from '@wordpress/i18n' |
| 2 | -import { isAxiosError } from 'axios' | |
| 2 | +import { isAxiosError, isCancel } from 'axios' | |
| 3 | 3 | |
| 4 | 4 | export const handleUnknownError = (error: unknown) => { |
| 5 | 5 | console.error(error) |
| 6 | 6 | } |
| 7 | + | |
| 8 | +/** | |
| 9 | + * Whether a rejection came from the caller aborting the request rather than | |
| 10 | + * from a failure — axios rejects cancelled requests with no response attached, | |
| 11 | + * so these must not be surfaced to the user as errors. | |
| 12 | + */ | |
| 13 | +export const isAbortError = (error: unknown): boolean => | |
| 14 | + isCancel(error) || error instanceof DOMException && 'AbortError' === error.name | |
| 7 | 15 | |
| 8 | 16 | export const unpackErrorResponse = (error: unknown): string => { |
| 9 | 17 | if (isAxiosError(error)) { |
| 10 | 18 | if (error.response) { |