PluginProbe
Code Snippets / 4.0.0-beta.2
Code Snippets v4.0.0-beta.2
4.0.0-beta.2 3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 3.0.0 All 65 releases
← All changes | js/utils/errors.ts +9 -1 3.10.2 → 4.0.0-beta.2 View file →
@@ -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) {