From a7d90344ae9e6bcfd70aca8bc6f6be07ec5393c3 Mon Sep 17 00:00:00 2001 From: Aadesh-Baral Date: Wed, 30 Aug 2023 11:10:40 +0545 Subject: [PATCH] Handle new error response format on frontend. ----------------------- After the introduction of new exception classes on backend the error response format is changed. As in new error response error subcode should be accessed on error.sub_code this commit handles this case. Also change in subcode to identify project is private and cannot be accessed by user has been addressed. --- frontend/src/network/tests/server-handlers.js | 2 +- frontend/src/utils/promise.js | 2 +- frontend/src/views/project.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/src/network/tests/server-handlers.js b/frontend/src/network/tests/server-handlers.js index c565d4cfb7..fdad0844f1 100644 --- a/frontend/src/network/tests/server-handlers.js +++ b/frontend/src/network/tests/server-handlers.js @@ -372,7 +372,7 @@ const faultyHandlers = [ return res.once( ctx.status(403), ctx.json({ - SubCode: `PrivateProject`, + error:{sub_code: `PRIVATE_PROJECT_NOT_ALLOWED`} }), ); }), diff --git a/frontend/src/utils/promise.js b/frontend/src/utils/promise.js index a9af63507a..2ee009b416 100644 --- a/frontend/src/utils/promise.js +++ b/frontend/src/utils/promise.js @@ -24,7 +24,7 @@ export async function handleErrors(response) { .clone() .json() .then((res) => { - text = res.SubCode || response.statusText; + text = res.error?.sub_code || res.SubCode || response.statusText; }); throw Error(text); } diff --git a/frontend/src/views/project.js b/frontend/src/views/project.js index 321bbd8826..ac80dd3fb8 100644 --- a/frontend/src/views/project.js +++ b/frontend/src/views/project.js @@ -198,7 +198,7 @@ export const ProjectDetailPage = () => { )} {error && ( <> - {error.message === 'PrivateProject' ? ( + {error.message === 'PRIVATE_PROJECT_NOT_ALLOWED' ? ( ) : (