Skip to content

Commit

Permalink
Merge pull request #279 from SELab-2/feature/forward-errors
Browse files Browse the repository at this point in the history
error handling
  • Loading branch information
Matthias-VE authored May 21, 2024
2 parents c0c96a9 + 8f81a87 commit 5598ce0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ docker.env
startBackend.sh

/.env
backend/web-bff/App/.env
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 5598ce0

Please sign in to comment.