From 8d595bb765cfdf1ebd113d7dd83e44270eab1852 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 19 Mar 2025 10:20:12 +0300 Subject: [PATCH] fix: display correct message for API reqeusts (#39786) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description Fixes an issue where incorrect/incomplete message is shown for API reponses. Fixes #39432 ## Automation /ok-to-test tags="@tag.IDE" ### :mag: Cypress test results > [!WARNING] > Workflow run: > Commit: 629191db7a352a05546d29b8b73b8020316226f2 > Cypress dashboard. > Tags: @tag.IDE > Spec: > It seems like **no tests ran** 😔. We are not able to recognize it, please check workflow here. >
Tue, 18 Mar 2025 14:44:01 UTC ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [ ] No ## Summary by CodeRabbit - **New Features** - Enhanced error reporting now displays a clear title alongside the detailed message, providing improved context for users encountering issues. - The streamlined error feedback offers a more structured presentation to help users better understand and address any problems. --- .../components/ErrorView/ErrorView.tsx | 4 +- .../utils/getErrorFromActionResponse.ts | 52 +++++++++++++------ 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/app/client/src/PluginActionEditor/components/PluginActionResponse/components/Response/components/ErrorView/ErrorView.tsx b/app/client/src/PluginActionEditor/components/PluginActionResponse/components/Response/components/ErrorView/ErrorView.tsx index 4d422de257..0f346021b6 100644 --- a/app/client/src/PluginActionEditor/components/PluginActionResponse/components/Response/components/ErrorView/ErrorView.tsx +++ b/app/client/src/PluginActionEditor/components/PluginActionResponse/components/Response/components/ErrorView/ErrorView.tsx @@ -32,7 +32,7 @@ export const ErrorView: React.FC = ({ handleJsonWrapperClick, tooltipContent, }) => { - const errorMessage = getErrorMessageFromActionResponse( + const [errorTitle, errorMessage] = getErrorMessageFromActionResponse( actionResponse, action.pluginType, ); @@ -79,7 +79,7 @@ export const ErrorView: React.FC = ({ Request has failed to execute {errorMessage && ":"} -
{errorMessage}
+
{errorTitle}
{ + return ( + pluginType === PluginType.DB || + pluginType === PluginType.SAAS || + pluginType === PluginType.EXTERNAL_SAAS || + pluginType === PluginType.API + ); +}; + /** * Retrieves the error message from the action response. + * Returns a tuple of [errorTitle, errorMessage] */ export const getErrorMessageFromActionResponse = ( actionResponse?: ActionResponse, pluginType?: PluginType, ) => { - // Return default error message if action response is not provided - if (!actionResponse) return DEFAULT_ERROR_MESSAGE; - - const { body, pluginErrorDetails } = actionResponse; - - if (pluginErrorDetails) { - // Return downstream error message if available - // Otherwise, return Appsmith error message - return ( - pluginErrorDetails.downstreamErrorMessage || - pluginErrorDetails.appsmithErrorMessage - ); + if (!actionResponse) { + return [DEFAULT_ERROR_MESSAGE, DEFAULT_ERROR_MESSAGE]; } - // Return body if plugin type is DB/SAAS/ExternalSAAS, otherwise return default error message - return pluginType === PluginType.DB || - pluginType === PluginType.SAAS || - pluginType === PluginType.EXTERNAL_SAAS + const { body, pluginErrorDetails, statusCode } = actionResponse; + + // Determine base error message based on plugin type + let errorMessage = isSupportedPluginTypeForErrorDetails(pluginType) ? body : DEFAULT_ERROR_MESSAGE; + + // Override with plugin-specific error details if available + if (pluginErrorDetails) { + errorMessage = + pluginErrorDetails.downstreamErrorMessage || + pluginErrorDetails.appsmithErrorMessage; + } + + // For API plugin types, use status code as the title + const errorTitle = pluginType === PluginType.API ? statusCode : errorMessage; + + return [errorTitle, errorMessage]; };