diff --git a/src/Components/HelperFunctions/getAxiosConfig.js b/src/Components/HelperFunctions/getAxiosConfig.js index e42656bb892b033f929ebd65d4267f1a56dc955a..f81cfbbd5a721a4bea846bdbe7f64d5e9bebd4c7 100644 --- a/src/Components/HelperFunctions/getAxiosConfig.js +++ b/src/Components/HelperFunctions/getAxiosConfig.js @@ -78,24 +78,39 @@ function updateAccessToken (newAccessToken) { } } -export const getRequest = (url, onSuccess, onError) => { - fetch((`${apiUrl}${url}`), { +export async function getRequest (url, onSuccess, onError) { + let response = await fetch((`${apiUrl}${url}`), { headers : fetchHeaders() }) - .then(response => { - if (response.headers.has('access-token')) { - updateAccessToken(response.headers.get('access-token')) - } - return response.json().catch(err => { - return {}; - }) - }) - .then(data => { - onSuccess(data) - }) - .catch(error => { - onError(error) - }) + if (response.ok) { + if (response.headers.has('access-token')) { + updateAccessToken(response.headers.get('access-token')) + } + + let json = await response.json() + onSuccess(json, response.headers) + } + else { + onError(response.error) + } + // .then(response => { + // if (response.headers.has('access-token')) { + // updateAccessToken(response.headers.get('access-token')) + // } + // let json = await response.json() + // + // onSuccess(json) + // + // return response.json().catch(err => { + // return {}; + // }) + // }) + // .then(data => { + // onSuccess(data) + // }) + // .catch(error => { + // onError(error) + // }) } export const deleteRequest = (url, onSuccess, onError) => {