Skip to content
Łukasz Witkowski edited this page Apr 25, 2021 · 18 revisions

Built in Exception Mappers

Here's a list of Exceptions for which this extension provides mappers, along with comparison between quarkus-resteasy-problem and raw quarkus-resteasy-jackson.

javax.validation.ConstraintViolationException

Thrown by Hibernate Validator (@Valid)

quarkus-resteasy-problem quarkus-resteasy-jackson
HTTP/1.1 400 Bad Request
Content-Type: application/problem+json

{
"status": 400,
"title": "Bad Request",
"instance": "/resource",
"violations" : [{
"field": "search_by",
"in": "query",
"message": "must be longer than 3"
}]
}
HTTP/1.1 400 Bad Request
validation-exception: true
Content-Type: application/json

{
"exception": null,
"propertyViolations": [],
"classViolations": [],
"parameterViolations": [{
"constraintType": "PARAMETER",
"path": "throwConstraintViolationException.arg0.key",
"message": "must be greater than or equal to 15",
"value": "10"
}],
"returnValueViolations": []
}

javax.validation.ValidationException

Thrown by Quarkus.

quarkus-resteasy-problem quarkus-resteasy-jackson
HTTP/1.1 400 Bad Request
Content-Type: application/problem+json

{
"status": 400,
"title": "Bad Request",
"detail": "Something is wrong",
"instance": "/resource"
}
HTTP/1.1 500 Internal Server Error
Content-Length: 49
validation-exception: true
Content-Type: text/plain;charset=UTF-8

javax.validation.ValidationException: A small one

javax.ws.rs.NotFoundException

Thrown by RESTeasy.

quarkus-resteasy-problem quarkus-resteasy-jackson
HTTP/1.1 404 Not Found
Content-Type: application/problem+json

{
"status": 404,
"title": "Not Found",
"detail": "RESTEASY003210: Could not find resource (...)",
"instance": "/resource"
}
HTTP/1.1 404 Not Found
Content-Length: 0

javax.ws.rs.RedirectionException

Thrown by Quarkus.

quarkus-resteasy-problem quarkus-resteasy-jackson
HTTP/1.1 301 Moved Permanently
Location: https://somewhere-else.com/
Pragma: no-cache
Cache-Control: no-store
Content-Type: application/problem+json

{
"status": 301,
"title": "Moved Permanently",
"instance": "/resource"
}
HTTP/1.1 301 Moved Permanently
Content-Length: 0
Location: http://localhost:8081/new-location

javax.ws.rs.WebApplicationException

Thrown by Quarkus/JaxRS.

quarkus-resteasy-problem quarkus-resteasy-jackson
HTTP/1.1 409 Conflict
Content-Type: application/problem+json

{
"status": 409,
"title": "Conflict",
"detail": "This is custom message",
"instance": "/resource"
}
HTTP/1.1 409 Conflict
Content-Length: 0

io.quarkus.security.AuthenticationFailedException / io.quarkus.security.AuthenticationCompletionExceptionMapper / io.quarkus.security.UnauthorizedException

Thrown by Quarkus if JWT token is missing or invalid.

quarkus-resteasy-problem quarkus-resteasy-jackson
HTTP/1.1 401 Unauthorized
Content-Type: application/problem+json

{
"status": 401,
"title": "Unauthorized",
"instance": "/resource"
}
HTTP/1.1 401 Unauthorized
www-authenticate: Bearer {token}
Content-Length: 0

io.quarkus.security.ForbiddenException

Thrown by Quarkus when @RolesAllowed not satisfied.

quarkus-resteasy-problem quarkus-resteasy-jackson
HTTP/1.1 403 Forbidden
Content-Type: application/problem+json

{
"status": 403,
"title": "Forbidden",
"instance": "/resource"
}
HTTP/1.1 403 Forbidden
Content-Length: 0

com.tietoevry.quarkus.resteasy.problem.HttpProblem

Example:

throw HttpProblem.builder()
    .withType(URI.create("/business-problem"))
    .withStatus(Status.CONFLICT)
    .withTitle("Business Conflict")
    .withDetail("Some business conflict has happened")
    .withInstance(URI.create("/problem/special-case"))
    .withHeader("X-RFC7807-Message", message)    
    .with("custom_property", 123)    
    .build();                    
quarkus-resteasy-problem quarkus-resteasy-jackson
HTTP/1.1 409 Conflict
X-Custom-Header: rfc7807-by-example
Content-Type: application/problem+json

{
"type": "/business-problem",
"status": 409,
"title": "Business Problem",
"detail": "Some business conflict has happened",
"instance": "/problem/special-case",
"custom_property": 123
}
not supported, http 500

org.zalando.problem.Problem

Example:

throw Problem.builder()
    .withType(URI.create("/business-problem"))
    .withStatus(Status.CONFLICT)
    .withTitle("Business Conflict")
    .withDetail("Some business conflict has happened")
    .withInstance(URI.create("/problem/special-case"))
    .with("custom_property", 123)    
    .build();
quarkus-resteasy-problem quarkus-resteasy-jackson
HTTP/1.1 409 Conflict
Content-Type: application/problem+json

{
"type": "/business-problem",
"status": 409,
"title": "Business Problem",
"detail": "Some business conflict has happened",
"instance": "/problem/special-case",
"custom_property": 123
}
not supported, http 500

java.lang.Throwable

Finally top-level exception mapper for all other exceptions throw by user or Quarkus.

quarkus-resteasy-problem quarkus-resteasy-jackson
HTTP/1.1 500 Internal Server Error
Content-Type: application/problem+json

{
"status": 500,
"title": "Internal Server Error",
"instance": "/resource"
}
HTTP/1.1 500 Internal Server Error
content-type: text/html; charset=utf-8

<html lang="en">
<head>
<title>Internal Server Error - Error handling ebcf54c0-1c84-4eb6-aa28-d62809a0577c-3, org.jboss.resteasy.spi.UnhandledException: (...)</title>
</head>
<body>
(...) whole stack trace (...)
<body>
Clone this wiki locally