diff --git a/src/helpers/api-client-helpers.ts b/src/helpers/api-client-helpers.ts index 3484916a..54d7e7d7 100644 --- a/src/helpers/api-client-helpers.ts +++ b/src/helpers/api-client-helpers.ts @@ -5,6 +5,7 @@ import { USER_AGENT } from '../constants' import { APIConfigurationParameters, DEFAULT_API_BASE_PATH, + ModelErrorContainer, SellingPartnerMismatchRegionError, SellingPartnerNotFoundRegionError, } from '../types' @@ -27,6 +28,16 @@ const regions = new Map( }), ) export class ApiClientHelpers { + static isAPIModelError( + axiosError: AxiosError, + ): axiosError is AxiosError { + const isError = (axiosError as AxiosError).response?.data.errors.every( + (element) => 'code' in element && 'message' in element, + ) + + return !!isError + } + static getAxiosInstance(parameters: APIConfigurationParameters): AxiosInstance { let axiosInstance: AxiosInstance const { axios } = parameters @@ -59,7 +70,11 @@ export class ApiClientHelpers { axiosInstance.interceptors.response.use( (response: AxiosResponse) => response, (error: AxiosError) => { - throw apiErrorFactory(error) + if (ApiClientHelpers.isAPIModelError(error)) { + throw apiErrorFactory(error) + } + + throw error }, )