Skip to content

fix: handle serverError in toast notifications for server actions#7612

Closed
Ltbltbltbltb wants to merge 2 commits intoformbricks:mainfrom
Ltbltbltbltb:fix/server-error-toast-handling
Closed

fix: handle serverError in toast notifications for server actions#7612
Ltbltbltbltb wants to merge 2 commits intoformbricks:mainfrom
Ltbltbltbltb:fix/server-error-toast-handling

Conversation

@Ltbltbltbltb
Copy link
Copy Markdown

@Ltbltbltbltb Ltbltbltbltb commented Mar 28, 2026

Summary

Fixes #3302 — Several components showed success toasts even when server actions returned serverError (HTTP 200 with error payload from next-safe-action).

Changes

Added serverError checks before success toasts in 8 components:

Component Action Before After
SingleResponseCard deleteResponseAction Toast success unconditionally Checks serverError first
EditProfileDetailsForm updateUserAction Toast success unconditionally Checks serverError first
edit-membership-role updateMembershipAction, updateInviteAction Silent failure Shows error toast
ResponseTable deleteResponseAction (callback) Toast success unconditionally Throws on error (caught by parent)
contacts-table deleteContactAction (callback) Toast success unconditionally Throws on error (caught by parent)
create-new-action-tab createActionClassAction Silent failure Shows error toast
survey-dropdown-menu copySurveyToOtherEnvironmentAction Checked data only — serverError showed success Checks serverError first
edit-language getSurveysUsingGivenLanguageAction Checked data only — serverError was silently ignored Checks serverError first

Pattern used

Follows the existing codebase pattern (~70% of components already use this):

const result = await someAction({...});
if (result?.serverError) {
  toast.error(getFormattedErrorMessage(result));
  return;
}
toast.success("...");

Test plan

  • Trigger ISE on each affected action and verify error toast appears
  • Verify success flow still works correctly
  • No regressions in existing toast behavior

/claim #3302

Several components showed success toasts even when server actions
returned serverError (HTTP 200 with error payload from next-safe-action).

Added serverError checks before success toasts in 6 components:
- SingleResponseCard (deleteResponse)
- EditProfileDetailsForm (updateUser)
- edit-membership-role (updateMembership, updateInvite)
- ResponseTable (deleteResponse callback)
- contacts-table (deleteContact callback)
- create-new-action-tab (createActionClass)

Fixes formbricks#3302
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Ltbltbltbltb seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@Ltbltbltbltb
Copy link
Copy Markdown
Author

I have signed the CLA.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 28, 2026

Walkthrough

The changes implement consistent server-side error handling across multiple components by introducing validation of results returned from server actions. The getFormattedErrorMessage helper was added to relevant imports. After each action call (delete, update, create operations), the result is now captured and checked for a serverError field. If present, a formatted error toast is displayed and execution exits early, preventing subsequent success logic from running. The existing success paths and try/catch exception handling remain unchanged.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive PR description covers what the change does, the pattern used, and a test plan, but lacks specific testing instructions and issue reference in the required format. Add explicit test steps in 'How should this be tested?' section with specific reproduction steps (e.g., 'Trigger ISE in EditProfileDetailsForm and verify error toast appears'). Include issue number in 'Fixes #(issue)' format at the top.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The PR title accurately describes the main change: adding serverError checks before showing success toasts in server action handlers.
Linked Issues check ✅ Passed All coding requirements from issue #3302 are met: components now check result?.serverError and show error toasts before proceeding to success logic.
Out of Scope Changes check ✅ Passed All changes are directly related to handling serverError in server actions across the six specified components; no out-of-scope modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/web/modules/survey/editor/components/create-new-action-tab.tsx (1)

82-91: 🧹 Nitpick | 🔵 Trivial

Typo in variable name: createActionClassResposne should be createActionClassResponse.

The serverError handling logic is correct, but the variable name has a typo that impacts code readability and consistency.

✏️ Proposed fix for the typo
-    const createActionClassResposne = await createActionClassAction({
+    const createActionClassResponse = await createActionClassAction({
       action: updatedAction,
     });

-    if (createActionClassResposne?.serverError) {
-      toast.error(getFormattedErrorMessage(createActionClassResposne));
+    if (createActionClassResponse?.serverError) {
+      toast.error(getFormattedErrorMessage(createActionClassResponse));
       return;
     }

-    if (!createActionClassResposne?.data) return;
+    if (!createActionClassResponse?.data) return;

-    const newActionClass = createActionClassResposne.data;
+    const newActionClass = createActionClassResponse.data;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/web/modules/survey/editor/components/create-new-action-tab.tsx` around
lines 82 - 91, There is a typo in the response variable name: rename all
instances of createActionClassResposne to createActionClassResponse (the const
assigned from await createActionClassAction({...}) and the subsequent checks
createActionClassResponse?.serverError and createActionClassResponse?.data) so
the variable name is consistent and readable; also update any other references
in this file that use the misspelled identifier (e.g., the
toast.error(getFormattedErrorMessage(...)) call) to use
createActionClassResponse.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@apps/web/modules/survey/editor/components/create-new-action-tab.tsx`:
- Around line 82-91: There is a typo in the response variable name: rename all
instances of createActionClassResposne to createActionClassResponse (the const
assigned from await createActionClassAction({...}) and the subsequent checks
createActionClassResponse?.serverError and createActionClassResponse?.data) so
the variable name is consistent and readable; also update any other references
in this file that use the misspelled identifier (e.g., the
toast.error(getFormattedErrorMessage(...)) call) to use
createActionClassResponse.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 22e7a784-eb00-4353-b8d3-e775f29a1bfd

📥 Commits

Reviewing files that changed from the base of the PR and between 01f765e and 00f7a97.

📒 Files selected for processing (6)
  • apps/web/app/(app)/environments/[environmentId]/settings/(account)/profile/components/EditProfileDetailsForm.tsx
  • apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/responses/components/ResponseTable.tsx
  • apps/web/modules/analysis/components/SingleResponseCard/index.tsx
  • apps/web/modules/ee/contacts/components/contacts-table.tsx
  • apps/web/modules/ee/role-management/components/edit-membership-role.tsx
  • apps/web/modules/survey/editor/components/create-new-action-tab.tsx

…s#3302)

Two locations were missed in the original fix for formbricks#3302:

- apps/web/modules/survey/list/components/survey-dropdown-menu.tsx:
  duplicateSurveyAndRefresh was showing success toast even when
  copySurveyToOtherEnvironmentAction returned a serverError.

- apps/web/modules/survey/multi-language-surveys/components/edit-language.tsx:
  handleDeleteLanguage was showing success UI even when
  getSurveysUsingGivenLanguageAction returned a serverError.

Both now follow the same pattern already used elsewhere in the codebase:
check serverError first with getFormattedErrorMessage(), then check data.
Copy link
Copy Markdown
Member

@Dhruwang Dhruwang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix. Looks good. 🚀

@Dhruwang
Copy link
Copy Markdown
Member

Merging duplicate here, since CLA is not signed.

@Dhruwang Dhruwang closed this Apr 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Internal Server Errors still shows success toast

4 participants