@transferwise/approve-api-action-helpers
Version:
An http client that handles SCA protected requests gracefully
29 lines (26 loc) • 523 B
JavaScript
function getDefaultHeaders() {
return {
'Content-Type': 'application/json',
};
}
class HTTPError extends Error {
constructor(response) {
super(response.statusText);
this.name = 'HTTPError';
this.response = response;
}
}
export function http(url, params = {}) {
return fetch(url, {
...params,
headers: {
...getDefaultHeaders(),
...params.headers,
},
}).then((response) => {
if (!response.ok) {
throw new HTTPError(response);
}
return response;
});
}