Closed tschaffter closed 1 year ago
This is our current schemas:
title:
type: string
description: A human readable documentation for the problem type
status:
type: integer
description: The HTTP status code
detail:
type: string
description: A human readable explanation specific to this occurrence of
the problem
type:
type: string
description: An absolute URI that identifies the problem type
Notes:
title
and status
should ideally be defined together.detail
should include resource object-specific information (e.g. "Challenge with ID 123 not found").type
could be used to capture the microservice error code if we decide to return it to the user. This may provide information about the underlying architecture that we don't necessarily want to expose to the user. This information may also be difficult to document for the same reason.~Spring Boost~ OpenAPI generator does not seem to support the MIME type application/problem+json
?
default ResponseEntity<OrganizationDto> getOrganization(Long organizationId) {
getRequest()
.ifPresent(
request -> {
for (MediaType mediaType : MediaType.parseMediaTypes(request.getHeader("Accept"))) {
if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
String exampleString = "{ \"name\" : \"DREAM\" }";
ApiUtil.setExampleResponse(request, "application/json", exampleString);
break;
}
if (mediaType.isCompatibleWith(MediaType.valueOf("application/problem+json"))) {
String exampleString =
"Custom MIME type example not yet supported: application/problem+json";
ApiUtil.setExampleResponse(request, "application/problem+json", exampleString);
break;
}
}
});
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
We have a schema for the error but the microservices are not implementing it. This schema was derived from RFC 7807.
Since then we adopted a microservice architecture. One of the error design proposed here is to add a global error code to the error object that enables to identify the microservice that reported the issue.
One important piece of information missing from our error schema is a timestamp.
Two fields that should be defined together in the RFC 7807 are the
title
andstatus
as highlighted in the following Java example from zalando/problem-spring-web:Here are error schemas used by GitHub:
Questions
application/json
?