Skip to content

[LSP-1319]: add wrapResponse utility and update handlers to use it and fix CORS issue#9

Merged
michael-puzon-resultscx merged 1 commit intomainfrom
LSP-1319
Mar 5, 2026
Merged

[LSP-1319]: add wrapResponse utility and update handlers to use it and fix CORS issue#9
michael-puzon-resultscx merged 1 commit intomainfrom
LSP-1319

Conversation

@michael-puzon-resultscx
Copy link
Copy Markdown
Contributor

##Background:
A reusable utility was needed to standardize API responses and error handling. Additionally, there were CORS issues affecting cross-origin requests, requiring a consistent solution for all endpoints.

##Changes:

  • Added a new wrapResponse utility in src/lib to wrap handler responses and errors.
  • Refactored handlers (e.g., osAutoSuggestHandler) to use the new wrapResponse utility.
  • Ensured all responses include proper CORS headers (Access-Control-Allow-Origin and Access-Control-Allow-Credentials) to resolve cross-origin issues.
  • Improved error logging and handling for better debugging and reliability.

Copilot AI review requested due to automatic review settings March 4, 2026 09:11
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a shared wrapResponse helper intended to standardize Lambda handler responses/errors and apply consistent CORS headers, and refactors the OpenSearch search + autosuggest handlers to use it.

Changes:

  • Added src/lib/wrap-response.js utility to wrap handler execution and format responses.
  • Refactored osSearchHandler to delegate response formatting/CORS to wrapResponse.
  • Refactored osAutoSuggestHandler to delegate response formatting/CORS to wrapResponse.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 9 comments.

File Description
src/lib/wrap-response.js New response wrapper that sets statusCode/body and adds CORS headers for success/error paths.
src/handlers/osSearchHandler.js Updated to use wrapResponse and return raw results instead of a proxy response object.
src/handlers/osAutoSuggestHandler.js Updated to use wrapResponse and return { suggestions, total } instead of a proxy response object.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@michael-puzon-resultscx michael-puzon-resultscx merged commit 98478a1 into main Mar 5, 2026
5 checks passed
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.

4 participants