@planet-a/affinity-node
Version:
API wrapper for the affinity.co API
15 lines (14 loc) • 503 B
JavaScript
import axios from 'axios';
import { AffinityApiError } from './errors.js';
const errorTransformer = (data, headers, status) => {
if (status && (status < 200 || status >= 300)) {
throw new AffinityApiError(status, data);
}
return data;
};
export const defaultTransformers = () => {
const { transformResponse = [] } = axios.defaults;
return Array.isArray(transformResponse)
? [...transformResponse, errorTransformer]
: [transformResponse, errorTransformer];
};