Guest User

Untitled

a guest
Sep 26th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. .then(response => {
  2. // Throw error cases as exceptions
  3. if (response.status === 401) {
  4. throw new Error('Unauthorized')
  5. }
  6. if (response.status != 200) {
  7. throw new Error('Server Error')
  8. }
  9. // Otherwise, just async parse the body to json
  10. return response.json()
  11. })
  12. .then(response => {
  13. // Success response
  14. })
  15. .catch(e => {
  16. // Failed response
  17. })
Add Comment
Please, Sign In to add comment