diff --git a/.changeset/hungry-crabs-repair.md b/.changeset/hungry-crabs-repair.md new file mode 100644 index 00000000000..dc05d579ebf --- /dev/null +++ b/.changeset/hungry-crabs-repair.md @@ -0,0 +1,7 @@ +--- +"@wso2is/admin.agents.v1": patch +"@wso2is/i18n": patch +"@wso2is/console": patch +--- + +Show a specific error message when agent creation fails because the organization's application limit has been reached, instead of the generic "Something went wrong" alert. diff --git a/features/admin.agents.v1/components/wizards/add-agent-wizard.tsx b/features/admin.agents.v1/components/wizards/add-agent-wizard.tsx index 5a567bca84e..a1dd30b8559 100644 --- a/features/admin.agents.v1/components/wizards/add-agent-wizard.tsx +++ b/features/admin.agents.v1/components/wizards/add-agent-wizard.tsx @@ -28,6 +28,7 @@ import { AppState } from "@wso2is/admin.core.v1/store"; import { AlertLevels, IdentifiableComponentInterface } from "@wso2is/core/models"; import { addAlert } from "@wso2is/core/store"; import { URLUtils } from "@wso2is/core/utils"; +import { AxiosError } from "axios"; import { CheckboxFieldAdapter, CheckboxGroupFieldAdapter, @@ -44,6 +45,7 @@ import { useDispatch, useSelector } from "react-redux"; import { Dispatch } from "redux"; import { Divider, Grid, Icon, Message } from "semantic-ui-react"; import { addAgent, updateAgentApplicationConfiguration } from "../../api/agents"; +import { AGENT_APP_LIMIT_REACHED_SCIM_TYPE } from "../../constants/agents"; import { AgentScimSchema, AgentType } from "../../models/agents"; import "./add-agent-wizard.scss"; @@ -168,18 +170,33 @@ const AddAgentWizard: FunctionComponent = ( setCreationResult(result); setIsShowingSuccessScreen(true); setIsSubmitting(false); - } catch (_err: unknown) { + } catch (error: unknown) { // On error, stay on form with the user's values. setIsShowingSuccessScreen(false); setCreationResult(null); setSubmittedValues(null); - dispatch( - addAlert({ - description: t("agents:wizard.alerts.error.description"), - level: AlertLevels.ERROR, - message: t("agents:wizard.alerts.error.message") - }) - ); + + const errorResponse: AxiosError<{ scimType?: string }>["response"] = + (error as AxiosError<{ scimType?: string }>)?.response; + + if (errorResponse?.status === 403 + && errorResponse?.data?.scimType === AGENT_APP_LIMIT_REACHED_SCIM_TYPE) { + dispatch( + addAlert({ + description: t("agents:wizard.alerts.limitReached.description"), + level: AlertLevels.ERROR, + message: t("agents:wizard.alerts.limitReached.message") + }) + ); + } else { + dispatch( + addAlert({ + description: t("agents:wizard.alerts.error.description"), + level: AlertLevels.ERROR, + message: t("agents:wizard.alerts.error.message") + }) + ); + } setIsSubmitting(false); } }; diff --git a/features/admin.agents.v1/constants/agents.ts b/features/admin.agents.v1/constants/agents.ts index e77f07b0e38..7466bf28b55 100644 --- a/features/admin.agents.v1/constants/agents.ts +++ b/features/admin.agents.v1/constants/agents.ts @@ -18,6 +18,12 @@ export const AGENT_SHARING_ERROR: string = "AGENT_SHARING_ERROR"; +/** + * SCIM `scimType` value returned when agent creation fails because the + * organization has reached its allowed application limit. + */ +export const AGENT_APP_LIMIT_REACHED_SCIM_TYPE: string = "applicationLimitReached"; + export const AGENT_FEATURE_DICTIONARY: Map = new Map() .set("AGENT_GROUPS", "agents.groups") .set("AGENT_SHARED_ACCESS", "agents.sharedAccess") diff --git a/modules/i18n/src/models/namespaces/agents-ns.ts b/modules/i18n/src/models/namespaces/agents-ns.ts index aceda2b80a1..52837708be3 100644 --- a/modules/i18n/src/models/namespaces/agents-ns.ts +++ b/modules/i18n/src/models/namespaces/agents-ns.ts @@ -116,6 +116,10 @@ export interface AgentsNS { message: string; description: string; }; + limitReached: { + message: string; + description: string; + }; clientIdFetchFailed: { message: string; description: string; diff --git a/modules/i18n/src/translations/en-US/portals/agents.ts b/modules/i18n/src/translations/en-US/portals/agents.ts index 3de3ee7f1bd..6efba0c5e10 100644 --- a/modules/i18n/src/translations/en-US/portals/agents.ts +++ b/modules/i18n/src/translations/en-US/portals/agents.ts @@ -208,6 +208,10 @@ export const agents: AgentsNS = { error: { description: "Creating agent failed", message: "Something went wrong" + }, + limitReached: { + description: "Agent application creation failed. Maximum application limit reached.", + message: "Application limit reached" } }, buttons: {