Skip to content

Conversation

@NSeydoux
Copy link
Contributor

@NSeydoux NSeydoux commented Apr 5, 2024

This adds boilerplate for the Problem Details consumption. This PR intentionally doesn't update SolidClient, and rather gets the underlying infrastructure in place first, so that the more meaningful changes to the behavior are focused and not drowned in setup code.

Specifically, this creates the ProblemDetails class, and updates the exception class hierarchy so that the SolidClientException child classes take a ProblemDetails instance in their constructor. The HttpStatus enum will be used to provide a default title to the ProblemDetails derived from a non-RFC9457 compliant response.

@NSeydoux NSeydoux force-pushed the JCL-460/problem-details-class branch 2 times, most recently from 0375861 to c9e8814 Compare April 11, 2024 09:00
*/
public BadRequestException(
final String message,
final ProblemDetails pd,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these exceptions that represent HTTP error statuses now have problem details.
But there is also an exception dedicated to carrying problem details introduced above.

Would it make sense to derive these HTTP error exceptions from the new ClientHttpException?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed the fact that they do in fact already derive.

import java.util.Optional;

enum HttpStatus {
BAD_REQUEST(BadRequestException.STATUS_CODE, "Bad Request"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it would make sense to flip this on its head:
That this enum has the actual status numbers and the exceptions refer to it.
Instead of the exception classes possessing the actual values.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, that's what I wanted to do initially, but then the SolidClientException::handle switch statement complains that a union member variable (e.g. HttpStatus.BAD_REQUEST.code) is not a constant. I preferred to keep that switch statement rather than a large if for readability, but I don't have a strong opinion one way or another.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I'm now revisiting this and I'm going to do as you suggest because I'm refactoring this to the api module so that it can be used in the jena and rdf4j packages too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in d568238

Comment on lines 10 to 38
public ClientHttpException(ProblemDetails problemDetails, String message) {
super(message);
this.problemDetails = problemDetails;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prepended the additional parameter here to keep the message, cause sequence in the overloaded constructor, but I notice none of the SolidClientExceptions expose a constructor taking a cause. Should the overloaded constructor be removed, and the order of parameters reversed?

import java.util.Arrays;
import java.util.Optional;

enum HttpStatus {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should a package-private enum have a Javadoc entry?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, no.
Except when you want to communicate something important to ourselves.

import java.util.Optional;

enum HttpStatus {
BAD_REQUEST(BadRequestException.STATUS_CODE, "Bad Request"),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, that's what I wanted to do initially, but then the SolidClientException::handle switch statement complains that a union member variable (e.g. HttpStatus.BAD_REQUEST.code) is not a constant. I preferred to keep that switch statement rather than a large if for readability, but I don't have a strong opinion one way or another.

@NSeydoux NSeydoux marked this pull request as ready for review April 11, 2024 12:44
@NSeydoux NSeydoux requested a review from a team as a code owner April 11, 2024 12:44
@NSeydoux NSeydoux force-pushed the JCL-460/problem-details-class branch from d7df055 to ad3551c Compare April 11, 2024 12:45
@NSeydoux NSeydoux changed the title JCL-460: Consume RFC9457 Problem Details response JCL-460: Initial support for RFC9457 Problem Details Apr 12, 2024
@NSeydoux NSeydoux marked this pull request as draft April 12, 2024 15:29
@NSeydoux NSeydoux force-pushed the JCL-460/problem-details-class branch from b67d8e1 to 208424d Compare April 13, 2024 20:56
The tests are in the solid-client module, because it will need the
additional json service anyways in the test dependencies for testing the
rest of this feature, and putting these tests in the api module creates
a circular dependency.
@NSeydoux NSeydoux marked this pull request as ready for review April 14, 2024 15:46
@NSeydoux
Copy link
Contributor Author

Split into #1160 and #1161 to ease review, as this PR was growing too large.

@NSeydoux NSeydoux closed this Apr 14, 2024
@acoburn acoburn deleted the JCL-460/problem-details-class branch May 29, 2024 18:54
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.

4 participants