I had previous verison of my code, that looked like this
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();
});
};
But after all I got an idea to refactor it, to that one
const getJSON = function (url, errorMsg = 'Something went wrong') {
return (async function () {
const response = await fetch(url);
if (!response.ok) throw new Error(`${errorMsg} (${response.status})`);
return response.json();
})();
};
So I’m curious, if my solution of refactor fine, using IIEF in this case.
There’s no error or something.