From 7d230d3dd46738a2672901a03729343f944c2784 Mon Sep 17 00:00:00 2001 From: Aruna Parameswaran Date: Thu, 20 Apr 2023 09:51:12 -0500 Subject: [PATCH 1/5] Updated frontend error message to be more verbose * Backend returns verbose logs, frontend displays it as generic messages depending on the HTTP status code * Updated the error message logic to include original backend logs wherever possible --- frontend/src/actions/common.js | 4 ++-- frontend/src/openapi/v2/core/request.ts | 16 +++++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/frontend/src/actions/common.js b/frontend/src/actions/common.js index dcbe6bbe9..140377e63 100644 --- a/frontend/src/actions/common.js +++ b/frontend/src/actions/common.js @@ -64,7 +64,7 @@ export function handleErrors(reason, originalFunc){ return (dispatch) => { dispatch({ type: NOT_AUTHORIZED, - reason: "Forbidden", + reason: reason.message !== undefined? reason.message : "Forbidden", stack: reason.stack ? reason.stack : "", receivedAt: Date.now() }); @@ -73,7 +73,7 @@ export function handleErrors(reason, originalFunc){ return (dispatch) => { dispatch({ type: NOT_FOUND, - reason: "Not Found", + reason: reason.message !== undefined? reason.message : "Not Found", stack: reason.stack ? reason.stack : "", receivedAt: Date.now() }); diff --git a/frontend/src/openapi/v2/core/request.ts b/frontend/src/openapi/v2/core/request.ts index 4c6e69dad..7c318ba32 100644 --- a/frontend/src/openapi/v2/core/request.ts +++ b/frontend/src/openapi/v2/core/request.ts @@ -225,12 +225,18 @@ function catchErrors(options: ApiRequestOptions, result: ApiResult): void { ...options.errors, } - const error = errors[result.status]; - if (error) { - throw new ApiError(result, error); - } - if (!result.ok) { + console.log(result) + const message = result.body.detail + const error = errors[result.status]; + + if (message) { + throw new ApiError(result, message); + + } else if (error) { + throw new ApiError(result, error); + } + throw new ApiError(result, 'Generic Error'); } } From f7c0e79887a9b96e636b1fe478003f40917f38cc Mon Sep 17 00:00:00 2001 From: Aruna Parameswaran Date: Thu, 20 Apr 2023 10:12:06 -0500 Subject: [PATCH 2/5] Fixed report button issue * Rootcause: The onClick event for the report button has a semantic error, which is causing the issue reason string to be replaced with an object * Also added encode for the reason --- frontend/src/components/Explore.tsx | 6 ++++-- frontend/src/components/datasets/CreateDataset.tsx | 6 ++++-- frontend/src/components/datasets/Dataset.tsx | 4 ++-- frontend/src/components/files/File.tsx | 4 ++-- frontend/src/components/listeners/ExtractionHistory.tsx | 6 ++++-- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/frontend/src/components/Explore.tsx b/frontend/src/components/Explore.tsx index 9b9fb53d0..600a887d3 100644 --- a/frontend/src/components/Explore.tsx +++ b/frontend/src/components/Explore.tsx @@ -63,8 +63,10 @@ export const Explore = (): JSX.Element => { setErrorOpen(false); } const handleErrorReport = () => { - window.open(`${config.GHIssueBaseURL}+${reason}&body=${encodeURIComponent(stack)}`); - } + window.open( + `${config.GHIssueBaseURL}+${encodeURIComponent(reason)}&body=${encodeURIComponent(stack)}` + ); + }; // fetch thumbnails from each individual dataset/id calls useEffect(() => { diff --git a/frontend/src/components/datasets/CreateDataset.tsx b/frontend/src/components/datasets/CreateDataset.tsx index 9f0fb70d3..226cc6bdf 100644 --- a/frontend/src/components/datasets/CreateDataset.tsx +++ b/frontend/src/components/datasets/CreateDataset.tsx @@ -51,8 +51,10 @@ export const CreateDataset = (): JSX.Element => { setErrorOpen(false); } const handleErrorReport = () => { - window.open(`${config.GHIssueBaseURL}+${reason}&body=${encodeURIComponent(stack)}`); - } + window.open( + `${config.GHIssueBaseURL}+${encodeURIComponent(reason)}&body=${encodeURIComponent(stack)}` + ); + }; // step 1 const onDatasetSave = (formData:any) =>{ diff --git a/frontend/src/components/datasets/Dataset.tsx b/frontend/src/components/datasets/Dataset.tsx index 04e8049da..ee268e4dd 100644 --- a/frontend/src/components/datasets/Dataset.tsx +++ b/frontend/src/components/datasets/Dataset.tsx @@ -111,9 +111,9 @@ export const Dataset = (): JSX.Element => { dismissError(); setErrorOpen(false); }; - const handleErrorReport = (reason: string) => { + const handleErrorReport = () => { window.open( - `${config.GHIssueBaseURL}+${reason}&body=${encodeURIComponent(stack)}` + `${config.GHIssueBaseURL}+${encodeURIComponent(reason)}&body=${encodeURIComponent(stack)}` ); }; diff --git a/frontend/src/components/files/File.tsx b/frontend/src/components/files/File.tsx index f0578008f..6bca93ea6 100644 --- a/frontend/src/components/files/File.tsx +++ b/frontend/src/components/files/File.tsx @@ -106,9 +106,9 @@ export const File = (): JSX.Element => { dismissError(); setErrorOpen(false); }; - const handleErrorReport = (reason: string) => { + const handleErrorReport = () => { window.open( - `${config.GHIssueBaseURL}+${reason}&body=${encodeURIComponent(stack)}` + `${config.GHIssueBaseURL}+${encodeURIComponent(reason)}&body=${encodeURIComponent(stack)}` ); }; diff --git a/frontend/src/components/listeners/ExtractionHistory.tsx b/frontend/src/components/listeners/ExtractionHistory.tsx index 0c72098f3..9f46490bc 100644 --- a/frontend/src/components/listeners/ExtractionHistory.tsx +++ b/frontend/src/components/listeners/ExtractionHistory.tsx @@ -163,8 +163,10 @@ export const ExtractionHistory = (): JSX.Element => { setErrorOpen(false); } const handleErrorReport = () => { - window.open(`${config.GHIssueBaseURL}+${reason}&body=${encodeURIComponent(stack)}`); - } + window.open( + `${config.GHIssueBaseURL}+${encodeURIComponent(reason)}&body=${encodeURIComponent(stack)}` + ); + }; return ( From 0ab4524aa8388169ab131788f13ab5aad63e964e Mon Sep 17 00:00:00 2001 From: Aruna Parameswaran Date: Wed, 26 Apr 2023 22:19:49 -0500 Subject: [PATCH 3/5] Fixing issue with error message --- frontend/src/actions/common.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/src/actions/common.js b/frontend/src/actions/common.js index 140377e63..6a5435bf1 100644 --- a/frontend/src/actions/common.js +++ b/frontend/src/actions/common.js @@ -64,7 +64,7 @@ export function handleErrors(reason, originalFunc){ return (dispatch) => { dispatch({ type: NOT_AUTHORIZED, - reason: reason.message !== undefined? reason.message : "Forbidden", + reason: reason.body.detail, stack: reason.stack ? reason.stack : "", receivedAt: Date.now() }); @@ -73,7 +73,7 @@ export function handleErrors(reason, originalFunc){ return (dispatch) => { dispatch({ type: NOT_FOUND, - reason: reason.message !== undefined? reason.message : "Not Found", + reason: reason.body.detail, stack: reason.stack ? reason.stack : "", receivedAt: Date.now() }); @@ -82,7 +82,7 @@ export function handleErrors(reason, originalFunc){ return (dispatch) => { dispatch({ type: FAILED, - reason: reason.message !== undefined? reason.message : "Backend Failure. Couldn't fetch!", + reason: reason.body.detail !== undefined? reason.body.detail : "Backend Failure. Couldn't fetch!", stack: reason.stack ? reason.stack : "", receivedAt: Date.now() }); From e7324741f836a98fd8f2d688c2f5bbfeee37bd84 Mon Sep 17 00:00:00 2001 From: Aruna Parameswaran Date: Wed, 26 Apr 2023 22:27:11 -0500 Subject: [PATCH 4/5] Revert "Updated frontend error message to be more verbose" This reverts commit 7d230d3dd46738a2672901a03729343f944c2784. --- frontend/src/actions/common.js | 4 ++-- frontend/src/openapi/v2/core/request.ts | 16 +++++----------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/frontend/src/actions/common.js b/frontend/src/actions/common.js index 6a5435bf1..84da51feb 100644 --- a/frontend/src/actions/common.js +++ b/frontend/src/actions/common.js @@ -64,7 +64,7 @@ export function handleErrors(reason, originalFunc){ return (dispatch) => { dispatch({ type: NOT_AUTHORIZED, - reason: reason.body.detail, + reason: "Forbidden", stack: reason.stack ? reason.stack : "", receivedAt: Date.now() }); @@ -73,7 +73,7 @@ export function handleErrors(reason, originalFunc){ return (dispatch) => { dispatch({ type: NOT_FOUND, - reason: reason.body.detail, + reason: "Not Found", stack: reason.stack ? reason.stack : "", receivedAt: Date.now() }); diff --git a/frontend/src/openapi/v2/core/request.ts b/frontend/src/openapi/v2/core/request.ts index 7c318ba32..4c6e69dad 100644 --- a/frontend/src/openapi/v2/core/request.ts +++ b/frontend/src/openapi/v2/core/request.ts @@ -225,18 +225,12 @@ function catchErrors(options: ApiRequestOptions, result: ApiResult): void { ...options.errors, } + const error = errors[result.status]; + if (error) { + throw new ApiError(result, error); + } + if (!result.ok) { - console.log(result) - const message = result.body.detail - const error = errors[result.status]; - - if (message) { - throw new ApiError(result, message); - - } else if (error) { - throw new ApiError(result, error); - } - throw new ApiError(result, 'Generic Error'); } } From 70a0ca9a02dcb37f2c7fe50d66fa0891c3e9e434 Mon Sep 17 00:00:00 2001 From: Aruna Parameswaran Date: Wed, 26 Apr 2023 22:27:51 -0500 Subject: [PATCH 5/5] Fixing issue with error message --- frontend/src/actions/common.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/actions/common.js b/frontend/src/actions/common.js index 84da51feb..6a5435bf1 100644 --- a/frontend/src/actions/common.js +++ b/frontend/src/actions/common.js @@ -64,7 +64,7 @@ export function handleErrors(reason, originalFunc){ return (dispatch) => { dispatch({ type: NOT_AUTHORIZED, - reason: "Forbidden", + reason: reason.body.detail, stack: reason.stack ? reason.stack : "", receivedAt: Date.now() }); @@ -73,7 +73,7 @@ export function handleErrors(reason, originalFunc){ return (dispatch) => { dispatch({ type: NOT_FOUND, - reason: "Not Found", + reason: reason.body.detail, stack: reason.stack ? reason.stack : "", receivedAt: Date.now() });