-
-
Save djetelina/d4b1b9f6ecb41e07d76844877ca36a02 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let fetchRses = (apiUrl, method) => { | |
return fetch('/rses/api' + apiUrl, {credentials: "include", method: method}) | |
.then(res => { | |
switch (res.status) { | |
case 403: | |
throw 'Unauthorized request'; | |
case 404: | |
throw 'Not found'; | |
case 200: | |
return res.json() | |
} | |
throw 'Unexpected error'; | |
}) | |
.then(out => { | |
console.debug(method + 'call @ ' + apiUrl + 'response: ', out); | |
console.log(out); | |
return out | |
}) | |
.catch(err => notifyError(err)); | |
}; | |
... | |
getIngredientTypeTotal () { | |
document.getElementById('ingredient-type-total').innerHTML = `<i class="fa fa-refresh fa-spin fa-fw"></i>`; | |
fetchRses('/list/total/ingredient_type', 'get') | |
.then(out => { | |
console.debug('getIngredientTypeTotal response'); | |
console.debug(out); | |
document.getElementById('ingredient-type-total').innerHTML = out.total; | |
}) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment