UNPKG

@yoroi/common

Version:
28 lines (26 loc) 947 B
"use strict"; import { Api } from '@yoroi/types'; import axios from 'axios'; import { ApiError } from '../errors/errors'; /** * @deprecated This function is deprecated and will be removed in a future release. Use `fetchData` instead. */ export const fetcher = async config => { try { const response = await axios(config); return response.data; } catch (error) { if (error.response) { // The request was made and the server responded with a status code // that falls out of the range of 2xx throw new ApiError(`Api error: ${error.response.data?.message} Status: ${error.response.status}`); } else if (error.request) { // The request was made but no response was received throw new Api.Errors.Network(); } else { // Something happened in setting up the request that triggered an Error throw new Error('An unknown error occurred'); } } }; //# sourceMappingURL=fetcher.js.map