Migrated ImageDownloader from axios to fetch

This commit is contained in:
Alejandro Celaya
2022-11-15 11:41:05 +01:00
parent a88ebc26a9
commit 34aa156d5f
9 changed files with 21 additions and 31 deletions

View File

@@ -1,4 +1,3 @@
import { AxiosError } from 'axios';
import {
ErrorTypeV2,
ErrorTypeV3,
@@ -11,15 +10,7 @@ import {
const isProblemDetails = (e: unknown): e is ProblemDetailsError =>
!!e && typeof e === 'object' && Object.keys(e).every((key) => ['type', 'detail', 'title', 'status'].includes(key));
const isAxiosError = (e: unknown): e is AxiosError<ProblemDetailsError> => !!e && typeof e === 'object' && 'response' in e;
export const parseApiError = (e: unknown): ProblemDetailsError | undefined => {
if (isProblemDetails(e)) {
return e;
}
return (isAxiosError(e) ? e.response?.data : undefined);
};
export const parseApiError = (e: unknown): ProblemDetailsError | undefined => (isProblemDetails(e) ? e : undefined);
export const isInvalidArgumentError = (error?: ProblemDetailsError): error is InvalidArgumentError =>
error?.type === ErrorTypeV2.INVALID_ARGUMENT || error?.type === ErrorTypeV3.INVALID_ARGUMENT;