video-ad-sdk
Version:
VAST/VPAID SDK that allows video ads to be played on top of any player
19 lines (18 loc) • 596 B
JavaScript
class FetchError extends Error {
constructor(message) {
super(message);
this.name = 'FetchError';
Object.setPrototypeOf(this, FetchError.prototype);
}
}
const BAD_REQUEST = 400;
export const fetch = async (endpoint, options = {}) => {
const fetchOptions = Object.assign({ credentials: 'include' }, options);
const response = await window.fetch(endpoint, fetchOptions);
if (response.status >= BAD_REQUEST) {
const error = new FetchError(response.statusText);
error.response = response;
throw error;
}
return response;
};