Skip to content

fix: preserve response body when error_status_codes triggers#668

Merged
bnusunny merged 1 commit intomainfrom
fix-error-status-codes-preserve-body
Mar 20, 2026
Merged

fix: preserve response body when error_status_codes triggers#668
bnusunny merged 1 commit intomainfrom
fix-error-status-codes-preserve-body

Conversation

@bnusunny
Copy link
Contributor

Problem

When AWS_LWA_ERROR_STATUS_CODES matched a response status code, the adapter discarded the HTTP response body and returned a generic error:

{"errorMessage": "Request failed with configured error status code: 500"}

This broke Step Functions workflows (and other consumers) that rely on error payloads for branching, retry logic, and error reporting.

Reported in #609.

Fix

The error now includes a JSON object with both the status code and the original response body:

{"statusCode": 502, "body": "Bad Gateway"}

For JSON response bodies, the body is properly escaped:

{"statusCode": 500, "body": "{\"code\":\"SERVICE_UNAVAILABLE\",\"detail\":\"Backend failed\"}"}

Changes

  • src/lib.rs: Collect response body before returning error; format as structured JSON with statusCode and body fields
  • Cargo.toml: Move http-body-util from dev-dependencies to dependencies (needed for BodyExt::collect())
  • tests/integ_tests/main.rs: Update existing test to verify response body is preserved in error

Testing

All 62 tests pass. The existing test_http_error_status_codes test now also asserts that the response body ("Bad Gateway") is present in the error message.

Fixes #609

Previously, when AWS_LWA_ERROR_STATUS_CODES matched a response status
code, the adapter discarded the HTTP response body and returned a
generic error message. This broke Step Functions workflows that rely
on error payloads for branching and retry logic.

Now the error includes a JSON object with both the status code and the
original response body:

  {"statusCode":502,"body":"Bad Gateway"}

This allows consumers like Step Functions to inspect the original error
details for decision making.

Fixes #609
@github-actions
Copy link

📊 Benchmark Comparison

Benchmark Details
  • Baseline: main branch
  • Comparison: This PR
  • Threshold: 10% regression triggers warning

@bnusunny bnusunny merged commit 028f205 into main Mar 20, 2026
7 checks passed
@bnusunny bnusunny deleted the fix-error-status-codes-preserve-body branch March 20, 2026 06:19
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.

Preserve Original Error Details

1 participant