From 79e50778f77aa0036910628598f884458c294706 Mon Sep 17 00:00:00 2001 From: Matthias-VE Date: Mon, 20 May 2024 23:52:41 +0200 Subject: [PATCH] error handling --- backend/web-bff/App/fetch.js | 12 +++++++++--- backend/web-bff/App/routes/api.js | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/backend/web-bff/App/fetch.js b/backend/web-bff/App/fetch.js index b32fc34d..5587ce1e 100644 --- a/backend/web-bff/App/fetch.js +++ b/backend/web-bff/App/fetch.js @@ -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; diff --git a/backend/web-bff/App/routes/api.js b/backend/web-bff/App/routes/api.js index 06b8c476..b15647ae 100644 --- a/backend/web-bff/App/routes/api.js +++ b/backend/web-bff/App/routes/api.js @@ -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); }