Created
September 5, 2018 21:38
-
-
Save dapperAuteur/1c3c8c57cb7dfb4c6df223d0015383c9 to your computer and use it in GitHub Desktop.
This file contains 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
async handleLoadPalabras() { | |
let fourLetterWords = await apiCalls.getPalabras('four-letter-words'); | |
let prefixSuffixRoots = await apiCalls.getPalabras('prefix-suffix-roots'); | |
let verbos = await apiCalls.getPalabras('verbos'); | |
this.setState({ | |
fourLetterWords, | |
prefixSuffixRoots, | |
verbos | |
}); | |
localStorage.setItem('fourLetterWords', JSON.stringify(fourLetterWords)); | |
localStorage.setItem('prefixSuffixRoots', JSON.stringify(prefixSuffixRoots)); | |
localStorage.setItem('verbos', JSON.stringify(verbos)); | |
} | |
export async function getPalabras(param) { | |
// console.log(param); | |
return fetch(`${APIURL}${param}`) | |
.then(resp => { | |
if (!resp.ok) { | |
if (resp.status >= 400 && resp.status < 500) { | |
return resp.json().then(data => { | |
let err = { errorMessage: data.message } | |
throw err; | |
}) | |
} else { | |
let err = { errorMessage: 'Please Try Again Later. Server Is NOT Responding.' }; | |
throw err; | |
} | |
} | |
return resp.json(); | |
}) | |
.catch(function (err) { | |
console.log(err); | |
return err; | |
}) | |
}` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment