From 2214abc1bf2d93d7df220e91c3179f24b746353a Mon Sep 17 00:00:00 2001 From: Manish Kumar <107841575+sondermanish@users.noreply.github.com> Date: Mon, 20 Nov 2023 09:26:45 +0530 Subject: [PATCH] fix: modified error code for unauthorised trigger and execute calls (#28946) ## Description > Introduced a new error to address Appsmith Error type handling Plugin authentication errors #### PR fixes following issue(s) Fixes # (issue number) #### Type of change - Bug fix (non-breaking change which fixes an issue) #### How Has This Been Tested? > Please describe the tests that you ran to verify your changes. Also list any relevant details for your test configuration. > Delete anything that is not relevant - [ ] Manual - [ ] JUnit - [ ] Jest - [ ] Cypress #### Issues raised during DP testing > Link issues raised during DP testing for better visiblity and tracking (copy link from comments dropped on this PR) > > > ## Checklist: #### Dev activity - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [ ] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed --- .../pluginExceptions/AppsmithPluginError.java | 9 +++++++++ .../pluginExceptions/AppsmithPluginErrorCode.java | 1 + .../java/com/external/plugins/OpenAiPlugin.java | 13 +++++++------ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/exceptions/pluginExceptions/AppsmithPluginError.java b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/exceptions/pluginExceptions/AppsmithPluginError.java index 802f016235..9f5b575b81 100644 --- a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/exceptions/pluginExceptions/AppsmithPluginError.java +++ b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/exceptions/pluginExceptions/AppsmithPluginError.java @@ -107,6 +107,15 @@ public enum AppsmithPluginError implements BasePluginError { ErrorType.AUTHENTICATION_ERROR, "{0}", "{1}"), + PLUGIN_DATASOURCE_AUTHENTICATION_ERROR( + 400, + AppsmithPluginErrorCode.PLUGIN_DATASOURCE_AUTHENTICATION_ERROR.getCode(), + "Invalid authentication credentials. Please check datasource configuration.", + AppsmithErrorAction.DEFAULT, + "Datasource authentication error", + ErrorType.DATASOURCE_CONFIGURATION_ERROR, + "{0}", + "{1}"), PLUGIN_DATASOURCE_ERROR( 400, AppsmithPluginErrorCode.PLUGIN_DATASOURCE_ERROR.getCode(), diff --git a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/exceptions/pluginExceptions/AppsmithPluginErrorCode.java b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/exceptions/pluginExceptions/AppsmithPluginErrorCode.java index 7e6465e4ab..7e482eefa3 100644 --- a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/exceptions/pluginExceptions/AppsmithPluginErrorCode.java +++ b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/exceptions/pluginExceptions/AppsmithPluginErrorCode.java @@ -17,6 +17,7 @@ public enum AppsmithPluginErrorCode { PLUGIN_DATASOURCE_TIMEOUT_ERROR("PE-DSE-5004", "Timed out when connecting to datasource"), PLUGIN_QUERY_TIMEOUT_ERROR("PE-QRY-5000", "Timed out on query execution"), PLUGIN_AUTHENTICATION_ERROR("PE-ATH-5000", "Datasource authentication error"), + PLUGIN_DATASOURCE_AUTHENTICATION_ERROR("PE-ATH-4000", "Datasource authentication error"), PLUGIN_DATASOURCE_ERROR("PE-DSE-4000", "Datasource error"), PLUGIN_UQI_WHERE_CONDITION_UNKNOWN("PE-UQI-5000", "Where condition could not be parsed"), GENERIC_STALE_CONNECTION("PE-STC-5000", "Secondary stale connection error"), diff --git a/app/server/appsmith-plugins/openAiPlugin/src/main/java/com/external/plugins/OpenAiPlugin.java b/app/server/appsmith-plugins/openAiPlugin/src/main/java/com/external/plugins/OpenAiPlugin.java index 22acc5f477..dc181441e4 100644 --- a/app/server/appsmith-plugins/openAiPlugin/src/main/java/com/external/plugins/OpenAiPlugin.java +++ b/app/server/appsmith-plugins/openAiPlugin/src/main/java/com/external/plugins/OpenAiPlugin.java @@ -111,8 +111,8 @@ public class OpenAiPlugin extends BasePlugin { if (HttpStatusCode.valueOf(401).isSameCodeAs(statusCode)) { actionExecutionResult.setIsExecutionSuccess(false); - actionExecutionResult.setErrorInfo( - new AppsmithPluginException(AppsmithPluginError.PLUGIN_AUTHENTICATION_ERROR)); + actionExecutionResult.setErrorInfo(new AppsmithPluginException( + AppsmithPluginError.PLUGIN_DATASOURCE_AUTHENTICATION_ERROR)); return Mono.just(actionExecutionResult); } @@ -183,8 +183,8 @@ public class OpenAiPlugin extends BasePlugin { return RequestUtils.makeRequest(httpMethod, uri, bearerTokenAuth, BodyInserters.empty()) .flatMap(responseEntity -> { if (responseEntity.getStatusCode().is4xxClientError()) { - return Mono.error( - new AppsmithPluginException(AppsmithPluginError.PLUGIN_AUTHENTICATION_ERROR)); + return Mono.error(new AppsmithPluginException( + AppsmithPluginError.PLUGIN_DATASOURCE_AUTHENTICATION_ERROR)); } if (!responseEntity.getStatusCode().is2xxSuccessful()) { @@ -237,12 +237,13 @@ public class OpenAiPlugin extends BasePlugin { } AppsmithPluginException error = - new AppsmithPluginException(AppsmithPluginError.PLUGIN_AUTHENTICATION_ERROR); + new AppsmithPluginException(AppsmithPluginError.PLUGIN_DATASOURCE_AUTHENTICATION_ERROR); return new DatasourceTestResult(error.getMessage()); }) .onErrorResume(error -> { if (!(error instanceof AppsmithPluginException)) { - error = new AppsmithPluginException(AppsmithPluginError.PLUGIN_AUTHENTICATION_ERROR); + error = new AppsmithPluginException( + AppsmithPluginError.PLUGIN_DATASOURCE_AUTHENTICATION_ERROR); } return Mono.just(new DatasourceTestResult(error.getMessage())); });