-
Notifications
You must be signed in to change notification settings - Fork 878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Timestamp field for exception handling #146
base: master
Are you sure you want to change the base?
Timestamp field for exception handling #146
Conversation
Thanks for your contibution @earlspilner What's more, for error handling, I wonder if we shouldn't switch to the RFC 9457 |
I'll work on this ;) |
Last commit introduce RFC 9457 Problem Details in To be perfectly honest, I'm not very familiar with JaCoCo, so would welcome advice on how this can be fixed P.S. From my own perch, I might suggest adding new exceptions when someone is not found (pet, vet, etc.) |
Hi @earlspilner In another Pull Request, we could update the openapi specification in order to align it with the RFC 9457. In this issue, to keep simple, I propose you could keep usage of the |
ProblemDetail problemDetail = ProblemDetail.forStatus(status); | ||
problemDetail.setTitle(title); | ||
problemDetail.setDetail(detail); | ||
problemDetail.setInstance(URI.create(request.getDescription(false).substring(4))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought: The "instance" member is a JSON string containing a URI reference that identifies the specific occurrence of the problem. See https://datatracker.ietf.org/doc/html/rfc9457#name-instance
We could host our own problem registry. For the beginning, I propose to use the Smartbear registry: https://problems-registry.smartbear.com/
I propose to postpone this change to another PR.
ErrorInfo errorInfo = new ErrorInfo(ex); | ||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(errorInfo); | ||
@ExceptionHandler(MethodArgumentNotValidException.class) | ||
public ResponseEntity<ProblemDetail> handleMethodArgumentNotValidException(MethodArgumentNotValidException ex, WebRequest request) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: It looks like the MethodArgumentNotValidException
had a body
property with the ProblemDetail
type.
I wonder if we can reuse it then complete it?
According to its constructor, the details
are very generic:
public MethodArgumentNotValidException(MethodParameter parameter, BindingResult bindingResult) {
super(bindingResult);
this.parameter = parameter;
this.body = ProblemDetail.forStatusAndDetail(getStatusCode(), "Invalid request content.");
}
I've added a new field to display the time at which the exceptional situation occurred.
It seems to look good ;)