Created checkStatusAndReturnJson middleware for checking for responses status is ok(200-299) or not and if it does returns a json parsed object.

This commit is contained in:
2019-11-25 23:28:23 +01:00
parent d0a251f69a
commit e7882869e6

View File

@@ -10,6 +10,13 @@ const ELASTIC_INDEX = config.ELASTIC_INDEX
// TODO
// - Move autorization token and errors here?
const checkStatusAndReturnJson = (response) => {
if (!response.ok) {
throw resp
}
return response.json()
}
// - - - TMDB - - -
/**
@@ -239,7 +246,6 @@ const login = (username, password) => {
}
return fetch(url.href, options)
.then(resp => checkStatus)
.then(resp => resp.json())
.catch(error => {
console.error('Unexpected error occured before receiving response. Error:', error)