Skip to content

Add support for custom error response from external registries#9270

Merged
hsbt merged 1 commit intoruby:masterfrom
luisgcoding:add-custom-header-error-response
Feb 13, 2026
Merged

Add support for custom error response from external registries#9270
hsbt merged 1 commit intoruby:masterfrom
luisgcoding:add-custom-header-error-response

Conversation

@luisgcoding
Copy link
Contributor

@luisgcoding luisgcoding commented Jan 27, 2026

What was the end-user or developer problem that led to this PR?

When gem fetching fails with HTTP errors, RubyGems currently displays the reasonPhrase field (e.g., "Forbidden", "Bad Request") from the HTTP/1.1 standard. External registries have to tweak this reasonPhrase field in order to send custom error message to the client (e.g: informing that a component was blocked by an internal policy violation). This approach has one issue: HTTP/2 removed the reasonPhrase field entirely (RFC 7540), so users only see numeric status codes like "403" without any descriptive text when using HTTP version 2, making the current workaround ineffective.

What is your fix for the problem, implemented in this PR?

This PR adds a new custom HTTP header called X-Error-Message. When present, the value from this header will be included in the error message displayed in the client's CLI instead of the reasonPhrase field.

For servers that do not send this header, the code maintains full backwards compatibility by falling back to the
current behavior (displaying the reasonPhrase from HTTP/1.1 or just the status code for HTTP/2).

This approach is already used by other major package management clients such as the Hugging Face CLI.

Alternate solution

Another approach would be to add support for RFC9457 (Problem Details for HTTP APIs), where RubyGems could check if the Content-Type has the value application/problem+json then parse the RFC9457 problem details response and display the information in a human-readable format to the client. However, the custom header approach was chosen for its simplicity and lower implementation overhead for both gem servers and the client. This could be another solution and I would like to hear from the community what are the thoughts about it.
This alternate solution was implemented in Maven.

Make sure the following tasks are checked

@hsbt hsbt force-pushed the add-custom-header-error-response branch from 0f108d9 to b021dde Compare February 13, 2026 06:29
@hsbt
Copy link
Member

hsbt commented Feb 13, 2026

I didn't know custom error response approach. I like X-Error-Message header because it's simple with the current implementation of RubyGems.

We can re-consider that with application/problem+json content-type if we need to more extra support.

@hsbt hsbt enabled auto-merge February 13, 2026 06:32
@hsbt hsbt merged commit 8f32bfe into ruby:master Feb 13, 2026
89 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants