From 834a7d3b69f5b915d6d7c3f837ddd07d2e2e2697 Mon Sep 17 00:00:00 2001 From: Alejandro Bailo <59607668+alejandrobailo@users.noreply.github.com> Date: Tue, 15 Jul 2025 17:58:50 +0200 Subject: [PATCH] fix(scans): capture 403 when no permissions (#8280) Co-authored-by: Pepe Fagoaga --- ui/CHANGELOG.md | 2 ++ ui/actions/scans/scans.ts | 13 +++++-------- .../launch-workflow/launch-scan-workflow-form.tsx | 6 ++---- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/ui/CHANGELOG.md b/ui/CHANGELOG.md index e98629166a..5dd58450b4 100644 --- a/ui/CHANGELOG.md +++ b/ui/CHANGELOG.md @@ -19,6 +19,8 @@ All notable changes to the **Prowler UI** are documented in this file. ### 🐞 Fixed +- Error message when launching a scan if user has no permissions [(#8280)](https://github.com/prowler-cloud/prowler/pull/8280) + ### Removed --- diff --git a/ui/actions/scans/scans.ts b/ui/actions/scans/scans.ts index 6d37fed0d7..c76ae42839 100644 --- a/ui/actions/scans/scans.ts +++ b/ui/actions/scans/scans.ts @@ -144,21 +144,18 @@ export const scanOnDemand = async (formData: FormData) => { }); if (!response.ok) { - try { - const errorData = await response.json(); - throw new Error(errorData?.message || "Failed to start scan"); - } catch { - throw new Error("Failed to start scan"); - } + const errorData = await response.json(); + + return { success: false, error: errorData.errors[0].detail }; } const data = await response.json(); - revalidatePath("/scans"); + return parseStringify(data); } catch (error) { - // eslint-disable-next-line no-console console.error("Error starting scan:", error); + return { error: getErrorMessage(error) }; } }; diff --git a/ui/components/scans/launch-workflow/launch-scan-workflow-form.tsx b/ui/components/scans/launch-workflow/launch-scan-workflow-form.tsx index 74bfbf8fde..bca5c061b5 100644 --- a/ui/components/scans/launch-workflow/launch-scan-workflow-form.tsx +++ b/ui/components/scans/launch-workflow/launch-scan-workflow-form.tsx @@ -63,13 +63,11 @@ export const LaunchScanWorkflow = ({ const data = await scanOnDemand(formData); - if (data?.errors && data.errors.length > 0) { - const error = data.errors[0]; - const errorMessage = `${error.detail}`; + if (data?.error) { toast({ variant: "destructive", title: "Oops! Something went wrong", - description: errorMessage, + description: data.error, }); } else { toast({