api7 / api7/aisix

Upstream errors with an empty body render an empty error.message

Open Beginner friendly
#952 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement P2
Dominant language
Rust
Stars
157
Forks
32
Avg merge
1h 25m
Merged PRs (30d)
145

Description

What

When an upstream answers with a non-2xx and an empty body, the client-visible envelope carries an empty message:

{"error":{"message":"","type":"upstream_error","code":""}}

capture_upstream_error_http (crates/aisix-gateway/src/bridge.rs) builds message from the response body alone, so there is nothing to render when the body is empty. The log line is fine — BridgeError's Display is upstream returned HTTP <status>: — but the caller gets a well-formed error envelope that says nothing.

How it surfaces

Any bodyless upstream error reaches it, but the case that made it visible is a redirect: after api7/aisix#951 an upstream 3xx surfaces as an upstream status instead of being followed, and a 301 with only a Location header is the single most likely bodyless response a provider endpoint returns. A caller then sees a 502 whose message is the empty string, with no hint that the configured endpoint is redirecting.

Suggested fix

Fall back to the status' canonical reason phrase when the body yields no message, e.g. upstream returned 301 Moved Permanently. Deliberately not echoing the Location value: it names a host the operator has not configured, and the gateway does not otherwise expose it.

This changes the rendered message for every empty-bodied upstream error, not only 3xx, which is why it was left out of #951 rather than widened into it.

Size

Small; the renderer is one function and the assertion surface is the error-envelope e2e (error-envelope-normalization-e2e).

Found by the independent pre-merge audit of #951 (LOW-2).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in crates/aisix-gateway/src/bridge.rs at capture_upstream_error_http and inspect how an empty response body becomes the client-visible message. Run the error-envelope-normalization-e2e assertion surface, then verify that bodyless non-2xx responses render the status reason phrase while existing non-empty errors remain unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
api, backend, testing-qa
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
75/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.