Skip to content

Instantly share code, notes, and snippets.

@djetelina
Last active May 19, 2017 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djetelina/d4b1b9f6ecb41e07d76844877ca36a02 to your computer and use it in GitHub Desktop.
Save djetelina/d4b1b9f6ecb41e07d76844877ca36a02 to your computer and use it in GitHub Desktop.
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