Use APi v3 by default, and fall back to v2 in case of not found errors

This commit is contained in:
Alejandro Celaya
2022-10-12 10:19:54 +02:00
parent da6d45a72c
commit d64abeecdc
4 changed files with 60 additions and 14 deletions

View File

@@ -1,5 +1,5 @@
import { AxiosError } from 'axios';
import { InvalidArgumentError, InvalidShortUrlDeletion, ProblemDetailsError } from '../types';
import { InvalidArgumentError, InvalidShortUrlDeletion, ProblemDetailsError, RegularNotFound } from '../types';
export const parseApiError = (e: AxiosError<ProblemDetailsError>) => e.response?.data;
@@ -8,3 +8,6 @@ export const isInvalidArgumentError = (error?: ProblemDetailsError): error is In
export const isInvalidDeletionError = (error?: ProblemDetailsError): error is InvalidShortUrlDeletion =>
error?.type === 'INVALID_SHORTCODE_DELETION' || error?.type === 'INVALID_SHORT_URL_DELETION';
export const isRegularNotFound = (error?: ProblemDetailsError): error is RegularNotFound =>
error?.type === 'NOT_FOUND' && error?.status === 404;