Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .then(response => {
- // Throw error cases as exceptions
- if (response.status === 401) {
- throw new Error('Unauthorized')
- }
- if (response.status != 200) {
- throw new Error('Server Error')
- }
- // Otherwise, just async parse the body to json
- return response.json()
- })
- .then(response => {
- // Success response
- })
- .catch(e => {
- // Failed response
- })
Add Comment
Please, Sign In to add comment