Skip to content

fix(server): fixed syntax error to comply with salesforce commerce cloud code definition#1384

Open
azhuravlov wants to merge 1 commit into
Adyen:developfrom
azhuravlov:bugfix/webhook-notification-syntax
Open

fix(server): fixed syntax error to comply with salesforce commerce cloud code definition#1384
azhuravlov wants to merge 1 commit into
Adyen:developfrom
azhuravlov:bugfix/webhook-notification-syntax

Conversation

@azhuravlov
Copy link
Copy Markdown

Summary

Following the cartridge upgrade for a customer leveraging Salesforce Commerce Cloud, we detected a server-side error in the logs after go-live, indicating a scripting failure.

Screenshot 2025-08-07 at 12 06 52 PM

Tested scenarios

  1. If the handle notification function returns an unsuccessful result.
  2. If the authentication check for the notification webhook fails.

Reference to the SFRA repository:

  1. storefront-reference-architecture/cartridges/modules/server/response.js render function definition;
  2. storefront-reference-architecture/cartridges/modules/server/response.js setStatusCode function definition;

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @azhuravlov, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This PR addresses a server-side scripting error encountered in Salesforce Commerce Cloud after a cartridge upgrade. The issue stemmed from an incorrect method call ('res.status' instead of 'res.setStatusCode') when handling webhook notifications, leading to a server error. My changes correct this syntax to ensure compliance with the Salesforce Commerce Cloud code definition and proper error handling.

Highlights

  • Error Handling Fix: I've updated the 'notify.js' file to replace the 'res.status(403)' call with 'res.setStatusCode(403)'. This aligns the code with the Salesforce Commerce Cloud framework's expected method for setting HTTP status codes, resolving a server-side scripting error.
  • Test Mock Update: I've modified the 'notify.test.js' file to reflect the changes in the 'res' object. The mock now includes 'setStatusCode' and 'json' functions, and the 'status' function has been removed, ensuring tests accurately simulate the updated 'res' behavior.
  • Webhook Response Finalization: I've added 'return this.done(req, res);' after rendering error pages in 'notify.js' when HMAC verification fails or notification processing is unsuccessful. This ensures the request-response cycle is properly finalized according to the SFRA pattern.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Aug 7, 2025

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly fixes a TypeError by replacing the incorrect res.status() method with res.setStatusCode() to comply with the Salesforce Commerce Cloud API. The corresponding test mocks are also updated appropriately. However, the fix introduces a critical regression by using this.done(), which will cause a new TypeError because this is not bound correctly in the middleware function's context. I've provided a suggestion to resolve this to ensure the webhook handler functions correctly.

Comment on lines +25 to +27
res.setStatusCode(403);
res.render('/adyen/error');
return this.done(req, res);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

critical

The use of this.done(req, res) will cause a TypeError because this is not bound to a controller instance in this middleware function. This will crash the notification handling when authentication fails.

To maintain consistency with the control flow in the rest of the function, which calls next() after rendering a response, you should call next() here to properly proceed to the next middleware in the chain after sending the response.

Suggested change
res.setStatusCode(403);
res.render('/adyen/error');
return this.done(req, res);
res.setStatusCode(403);
res.render('/adyen/error');
return next();

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.

1 participant