FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

JCL-460: Initial support for RFC9457 Problem Details by NSeydoux · Pull Request #1138 · inrupt/solid-client-java · GitHub

Repository navigation

JCL-460: Initial support for RFC9457 Problem Details - #1138

Closed
NSeydoux wants to merge 18 commits into
mainfrom
JCL-460/problem-details-class
Closed

NSeydoux wants to merge 18 commits into
mainfrom
JCL-460/problem-details-class

Conversation

NSeydoux commented Apr 5, 2024 •
edited
Loading

Copy link
Copy Markdown
Contributor

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 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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Done in d568238

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Should a package-private enum have a Javadoc entry?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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 marked this pull request as ready for review April 11, 2024 12:44
NSeydoux requested a review from a team as a code owner April 11, 2024 12:44
NSeydoux force-pushed the JCL-460/problem-details-class branch from d7df055 to ad3551c Compare April 11, 2024 12:45
NSeydoux changed the title JCL-460: Consume RFC9457 Problem Details response JCL-460: Initial support for RFC9457 Problem Details Apr 12, 2024
NSeydoux marked this pull request as draft April 12, 2024 15:29
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 marked this pull request as ready for review April 14, 2024 15:46

Copy link
Copy Markdown
Contributor Author

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

NSeydoux closed this Apr 14, 2024
acoburn deleted the JCL-460/problem-details-class branch May 29, 2024 18:54
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

3 participants


Back | FazBrowse Home | New Git URL