24 lines
776 B
TypeScript
24 lines
776 B
TypeScript
import { AxiosError } from 'axios';
|
|
|
|
/**
|
|
* Check if error is an AxiosError, and optional if a specific status was returned
|
|
*
|
|
* @param error Thrown error to check
|
|
* @param status If set, check if this error has set thouse status code
|
|
*/
|
|
export function isAxiosError(error: unknown, status?: number) {
|
|
// Check if it is an axios error (with axios 1.0 `error instanceof AxiosError` will be possible)
|
|
if (typeof error !== 'object' || !error || !('isAxiosError' in error)) return false;
|
|
// Check status code if status was given
|
|
if (status !== undefined)
|
|
return (
|
|
(<AxiosError>error).response !== undefined && (<AxiosError>error).response?.status === status
|
|
);
|
|
|
|
return true;
|
|
}
|
|
|
|
export * from './main';
|
|
export * from './session';
|
|
export * from './user';
|