Skip to content

fix[sfcc]: ENG-11447 surface specific auth errors and trim Einstein settings#4306

Merged
AishwaryaParab merged 2 commits intomainfrom
ENG-11447_sfcc_error_handling
Mar 2, 2026
Merged

fix[sfcc]: ENG-11447 surface specific auth errors and trim Einstein settings#4306
AishwaryaParab merged 2 commits intomainfrom
ENG-11447_sfcc_error_handling

Conversation

@AishwaryaParab
Copy link
Contributor

@AishwaryaParab AishwaryaParab commented Feb 27, 2026

Description

When Salesforce rejects authentication (e.g. "redirect_uri doesn't match the registered redirects"), the specific error message from Salesforce was available in the server response but was being discarded in validateConfig(), which always threw the same generic string regardless of the actual failure reason.

Changes:

  • validateConfig() now reads response.errors[0].title and appends the specific Salesforce reason to the error message shown to the user.
  • A second check is also added to catch a previously silent failure case where the server returns a { message } shaped response (e.g. when plugin settings are not found in Firestore). This was previously falling through without throwing any error.
  • Added .trim() when reading einsteinId and einsteinSiteId from settings, consistent with the existing pattern in the headless plugin.

JIRA Ticket:
https://builder-io.atlassian.net/browse/ENG-11447

Testing:
https://www.notion.so/builderio/Testing-SFCC-Plugin-3173d7274be5802bb5fdd27ddd35ad86


Note

Low Risk
Low risk: limited to config validation and settings parsing, with no changes to core commerce read/search flows. Main risk is rejecting configs that previously passed due to stricter response handling.

Overview
Improves Salesforce Commerce plugin config validation by treating both errors[] and unexpected { message } responses as authentication failures, and logging the Salesforce-provided failure detail to aid debugging.

Also trims whitespace from einsteinId and einsteinSiteId before deciding whether to enable Einstein recommenders, reducing failures caused by accidental spaces.

Written by Cursor Bugbot for commit a395b32. This will update automatically on new commits. Configure here.

@changeset-bot
Copy link

changeset-bot bot commented Feb 27, 2026

⚠️ No Changeset found

Latest commit: a395b32

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@nx-cloud
Copy link

nx-cloud bot commented Feb 27, 2026

View your CI Pipeline Execution ↗ for commit a395b32

Command Status Duration Result
nx test @e2e/qwik-city ✅ Succeeded 7m 33s View ↗
nx test @e2e/angular-17 ✅ Succeeded 6m 38s View ↗
nx test @e2e/nextjs-sdk-next-app ✅ Succeeded 6m 35s View ↗
nx test @e2e/nuxt ✅ Succeeded 5m 50s View ↗
nx test @e2e/gen1-remix ✅ Succeeded 5m 3s View ↗
nx test @e2e/react-sdk-next-15-app ✅ Succeeded 5m 8s View ↗
nx test @e2e/react-sdk-next-14-app ✅ Succeeded 4m 56s View ↗
nx test @e2e/angular-17-ssr ✅ Succeeded 5m 4s View ↗
Additional runs (37) ✅ Succeeded ... View ↗

☁️ Nx Cloud last updated this comment at 2026-03-02 06:22:05 UTC

}
async validateConfig() {
const response = await this.request(`validate-config`);
if (response.errors) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are the new changes type safe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the impl. and added checks for response.errors and other new changes.

Copy link
Contributor

@sanyamkamat sanyamkamat left a comment

Choose a reason for hiding this comment

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

plugins/salesforce-commerce-api-plugin/src/plugin.ts changes looks good to me. Just verify edge cases around the response.errors block updates.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

if (detail) {
console.error('[SFCommerce] Authentication failed. Salesforce error:', detail);
}
throw 'We failed to authenticate your access to Salesforce Commerce Cloud B2C API. Please review all plugin fields and make sure they are correct.';
Copy link

Choose a reason for hiding this comment

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

Specific Salesforce error detail not appended to thrown message

Medium Severity

The detail extracted from errors[0]?.title is only logged via console.error but is never appended to the thrown error string on line 101. The thrown message is the same generic string as before, so the user never sees the specific Salesforce reason. The PR description explicitly states the intent is to "append the specific Salesforce reason to the error message shown to the user," but the implementation only surfaces it in the developer console.

Fix in Cursor Fix in Web

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is intended. The error message in the popup will remain the same. More info will be provided in the console.

@AishwaryaParab AishwaryaParab merged commit ecf0648 into main Mar 2, 2026
48 checks passed
@AishwaryaParab AishwaryaParab deleted the ENG-11447_sfcc_error_handling branch March 2, 2026 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants