Skip to content

fix: preserve respond_with_error payloads#40

Merged
bougyman merged 1 commit intomainfrom
fix/respond-with-error-passthrough
Mar 31, 2026
Merged

fix: preserve respond_with_error payloads#40
bougyman merged 1 commit intomainfrom
fix/respond-with-error-passthrough

Conversation

@bougyman
Copy link
Copy Markdown
Member

Summary

  • stop coercing respond_with_error payloads to strings before handing them to nats-pure
  • forward blocks to the underlying NATS message so { code: 422, ... } payloads can be adjusted in place
  • preserve raised exceptions as exception objects and add regression coverage for hash failures and block passthrough

Testing

  • bundle exec rake test

Closes #39

Copilot AI review requested due to automatic review settings March 31, 2026 12:04
@bougyman bougyman force-pushed the fix/respond-with-error-passthrough branch from 10e3ed3 to e8107a6 Compare March 31, 2026 12:06
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 fixes respond_with_error behavior so error payloads (e.g., hashes with custom code) and raised exceptions are preserved as-is when passed through to nats-pure, enabling non-500 error codes and in-place adjustments via blocks.

Changes:

  • Stop coercing respond_with_error payloads to strings; pass objects (including Exceptions and Hashes) through unchanged.
  • Forward blocks from MessageWrapper#respond_with_error to the underlying NATS message error response.
  • Add regression tests covering exception passthrough, hash failure passthrough, and block forwarding.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
lib/leopard/message_wrapper.rb Removes string coercion and forwards optional blocks when responding with errors.
lib/leopard/nats_api_server.rb Preserves raised exceptions by passing the exception object (not its message) to respond_with_error.
test/lib/message_wrapper.rb Adds/updates tests to assert exceptions/hashes are passed through and blocks are forwarded.
test/lib/nats_api_server.rb Updates handler-raise test to assert exception object passthrough and adds hash-failure regression coverage.

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

@bougyman bougyman merged commit f5c0d46 into main Mar 31, 2026
4 checks passed
@bougyman bougyman deleted the fix/respond-with-error-passthrough branch March 31, 2026 12:14
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.

Allow any object with respond_with_error

3 participants