[JavaScript] Asynchronous JavaScript: Promises, Async/Await, and AJAX - Throwing Error Manually
Creating generic function
const getJSON = function (url, errorMsg = 'Something went wrong') {
return fetch(url).then(response => {
if (!response.ok) throw new Error(`${errorMsg} (${response.status})`);
return response.json();
});
};
Thro...
jaydenjpark.hashnode.dev1 min read