2020-12-22 01:51:35 +03:00
|
|
|
import { AxiosError } from 'axios';
|
2022-10-12 11:19:54 +03:00
|
|
|
import { InvalidArgumentError, InvalidShortUrlDeletion, ProblemDetailsError, RegularNotFound } from '../types';
|
2020-12-22 01:51:35 +03:00
|
|
|
|
|
|
|
export const parseApiError = (e: AxiosError<ProblemDetailsError>) => e.response?.data;
|
2020-12-22 11:49:13 +03:00
|
|
|
|
|
|
|
export const isInvalidArgumentError = (error?: ProblemDetailsError): error is InvalidArgumentError =>
|
|
|
|
error?.type === 'INVALID_ARGUMENT';
|
|
|
|
|
|
|
|
export const isInvalidDeletionError = (error?: ProblemDetailsError): error is InvalidShortUrlDeletion =>
|
2022-01-25 21:51:08 +03:00
|
|
|
error?.type === 'INVALID_SHORTCODE_DELETION' || error?.type === 'INVALID_SHORT_URL_DELETION';
|
2022-10-12 11:19:54 +03:00
|
|
|
|
|
|
|
export const isRegularNotFound = (error?: ProblemDetailsError): error is RegularNotFound =>
|
|
|
|
error?.type === 'NOT_FOUND' && error?.status === 404;
|