Skip to content

Commit

Permalink
error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias-VE committed May 20, 2024
1 parent 31b9290 commit 79e5077
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions backend/web-bff/App/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,17 @@ async function fetch(endpoint, accessToken, method, body, headers) {
console.log(`${method} request made to ${BACKEND_API_ENDPOINT}/${endpoint} at: ` + new Date().toString());

try {
const response = await axios(config);
return await response.data;
const res = await axios(config)
return {code: res.status, data: res.data}
} catch (error) {
throw new Error(error);
if (error.response) {
return {code: error.response.status, data: error.response.data}
} else {
throw Error(error);
}
}


}

module.exports = fetch;
2 changes: 1 addition & 1 deletion backend/web-bff/App/routes/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ router.all('/*',

try {
const response = await fetch( "api" + req.url , req.session.accessToken, req.method, req.body, req.headers)
res.send(response)
res.status(response.code).send(response.data)
} catch(error) {
next(error);
}
Expand Down

0 comments on commit 79e5077

Please sign in to comment.