Skip to content

feat(statusx): expose error metadata via x-status-metadata response header#593

Merged
dorothyyzh merged 1 commit into
masterfrom
feat/statusx-metadata-header
Jun 16, 2026
Merged

feat(statusx): expose error metadata via x-status-metadata response header#593
dorothyyzh merged 1 commit into
masterfrom
feat/statusx-metadata-header

Conversation

@dorothyyzh

Copy link
Copy Markdown
Contributor

What

On the vproto HTTP error path, error metadata set via statusx.WithMetadata was being dropped, because vproto.ValidationError has no metadata field. This exposes it out-of-band on a response header.

  • Set x-status-metadata (JSON-encoded, URL-escaped map[string]string) on the response, only when the error actually carries metadata.
  • Add var ExposedHeaders (symmetric to the existing var AllowHeaders) so downstreams using the vproto path can concat it into their CORS ExposedHeaders.

Why this lives in statusx, not httpx

The connect protocol path already carries metadata natively in the error details (see ConvertToConnectError), so it needs no header. Only the vproto path needs this workaround, because its message schema lacks the field.

That means it would be wrong to wire the header into httpx.Security (the generic CORS middleware) — a service that doesn't use vproto would get an x-status-metadata header exposed that it never sets. The header is part of statusx's error protocol, so its ownership and its ExposedHeaders declaration stay in statusx. httpx is left untouched. Downstreams that use the vproto path opt in by adding statusx.ExposedHeaders to their CORS config.

Test

  • TestWriteVProtoHTTPError_MetadataHeader: header is set with the correct encoding when metadata is present, and omitted when absent.

🤖 Generated with Claude Code

…eader

vproto.ValidationError has no metadata field, so metadata set via
statusx.WithMetadata would be lost on the vproto HTTP error path (unlike
the connect path, which carries it natively in error details). Expose it
out-of-band on the x-status-metadata response header: a JSON-encoded,
URL-escaped map[string]string, set only when the error carries metadata.

Add var ExposedHeaders (symmetric to AllowHeaders) so downstreams using
the vproto path can wire the header into their CORS ExposedHeaders. The
header ownership stays in statusx; httpx is left unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@dorothyyzh dorothyyzh merged commit 6aa8829 into master Jun 16, 2026
7 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.

2 participants