fix(server): fixed syntax error to comply with salesforce commerce cloud code definition#1384
fix(server): fixed syntax error to comply with salesforce commerce cloud code definition#1384azhuravlov wants to merge 1 commit into
Conversation
…oud code definition
There was a problem hiding this comment.
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
-
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. ↩
|
There was a problem hiding this comment.
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.
| res.setStatusCode(403); | ||
| res.render('/adyen/error'); | ||
| return this.done(req, res); |
There was a problem hiding this comment.
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.
| res.setStatusCode(403); | |
| res.render('/adyen/error'); | |
| return this.done(req, res); | |
| res.setStatusCode(403); | |
| res.render('/adyen/error'); | |
| return next(); |



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.
Tested scenarios
Reference to the SFRA repository: