apiref
is-axios-error@1.0.0

isAxiosError()  Function

Returns whether the given error is an AxiosError. Can be used to narrow the type of the error.

Signature

export declare function isAxiosError(e: any, status?: number): e is AxiosError;

Example

try {
  await axios.get('https://example.com/thing.txt')
  return true
} catch (e: unknown) {
  if (!isAxiosError(e, 404)) throw e
  return false
}

Parameters

ParameterTypeDescription
eany

The error to check.

statusnumber

An expected status code to check for. If not provided, any status code will be accepted.

(Returns)e is AxiosError

Whether the given error is an AxiosError.