Skip to content

[Feature]: improve error messages for HTTP URL connections #824

@ascopes

Description

@ascopes

Brief description

HTTP URL connections that fail due to a 4xx or 5xx will currently raise a blind exception due to input streams being closed. This is overly unhelpful.

We should override the URL connection logic to handle the error stream sensibly, since this is a custom component of HTTP URL connections specifically.

Aims and goals

Provide better error messages for bad URLs.

Useful information to include in error messages

  • Status code
  • Reason, if provided
  • Correlation ID headers if available (/.*Correlation[_-]?Id.*/i)
  • Request ID headers if available (/.*Request[_-]Id.*/i)
  • WWW-Authenticate header, if provided
  • Proxy-Authenticate header, if provided
  • Response body from error stream (truncate if too long)

Workarounds

Checking manually with cURL.

Considerations

It may be more erganomic to write a URLConnection that wraps the Java 11 HttpClient API instead of hacking around with wrapping the existing URLConnnection implementation.

  • This will allow for using HTTP/2 as well (and eventually HTTP/3 over QUIC once OpenJDK supports it).
  • HttpClient can be kept alive for the duration of the URLStreamHandlerFactory to share connections, although we will have to remember to create any shutdown hooks we require.

Assess during the implementation.

Requirements

Would you like to contribute to this feature?

  • Yes, I'd like to contribute this change myself!

Metadata

Metadata

Assignees

Labels

good first issueGood issues for new contributors to pick up.new featureA new user-facing feature.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions