UNPKG

@speechkit/speechkit-audio-player

Version:

A web player component that can play audio from https://speechkit.io

24 lines (22 loc) 633 B
// Util for fetch, which invludes handling of errors // allows for simpler, more readable fetch calls import 'whatwg-fetch' // check response on every request and only return if valid // otherwise throw error with statusText const handleErrors = response => { if (response.status >= 200 && response.status < 300) { return response; } else { var error = new Error(response.statusText + response.status) error.response = response; throw error; } } // url, init=headers etc. const fetchWithErrorHandling = (url, init) => { return fetch(url, init) .then(handleErrors); } export { fetchWithErrorHandling, }