-
Notifications
You must be signed in to change notification settings - Fork 24
Closed
Labels
good first issueGood issues for new contributors to pick up.Good issues for new contributors to pick up.new featureA new user-facing feature.A new user-facing feature.
Description
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
- New class extending URLStreamHandlerFactory at https://github.com/ascopes/protobuf-maven-plugin/tree/main/protobuf-maven-plugin/src/main/java/io/github/ascopes/protobufmavenplugin/urls to wrap an HTTP(S) connection
- Should open a regular HTTPURLConnection, but have logic in the .connect() method of the returned URL to handle reporting errors better.
- 404s should raise FileNotFoundException as they already do internally
- Add unit tests
- Register new class under
"http"and"https"protocols in https://github.com/ascopes/protobuf-maven-plugin/tree/main/protobuf-maven-plugin/src/main/java/io/github/ascopes/protobufmavenplugin/urls/UrlFactory.java
Would you like to contribute to this feature?
- Yes, I'd like to contribute this change myself!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
good first issueGood issues for new contributors to pick up.Good issues for new contributors to pick up.new featureA new user-facing feature.A new user-facing feature.