How can i use this method from my own project/design
Github.prototype.handleErr = function(res) {
if(!res.ok) {
throw new Error('Something went wrong!!' + res.status);
}
return res;
}
Inside another method but the same object
const git = new Github();
Github.prototype.getUser = (user) => {
return new Promise((resolve, reject) => {
// Profile
fetch(something)
.then(this.handleErr)
.then(response => response.json())
.then(data => resolve(data))
.catch(err => reject(err));
})
}
it didn't work with this.handleErr
i wanted to make a fetch request and use the git.handleErr()
function inside .then()
consumer, before handling the data response.