forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request quarkusio#15278 from gytis/rest-data-panache-excep…
…tion-mapping Wrap REST Data Panache exceptions for handling
- Loading branch information
Showing
16 changed files
with
318 additions
and
150 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
48 changes: 48 additions & 0 deletions
48
...va/io/quarkus/hibernate/orm/rest/data/panache/runtime/RestDataPanacheExceptionMapper.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package io.quarkus.hibernate.orm.rest.data.panache.runtime; | ||
|
||
import javax.persistence.PersistenceException; | ||
import javax.transaction.RollbackException; | ||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.ext.ExceptionMapper; | ||
|
||
import org.hibernate.exception.ConstraintViolationException; | ||
|
||
import io.quarkus.arc.ArcUndeclaredThrowableException; | ||
import io.quarkus.rest.data.panache.RestDataPanacheException; | ||
|
||
public class RestDataPanacheExceptionMapper implements ExceptionMapper<RestDataPanacheException> { | ||
@Override | ||
public Response toResponse(RestDataPanacheException exception) { | ||
exception.printStackTrace(); | ||
|
||
if (exception.getCause() instanceof ArcUndeclaredThrowableException) { | ||
return toResponse((ArcUndeclaredThrowableException) exception.getCause(), exception.getMessage()); | ||
} | ||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), exception.getMessage()).build(); | ||
} | ||
|
||
private Response toResponse(ArcUndeclaredThrowableException exception, String message) { | ||
if (exception.getCause() instanceof RollbackException) { | ||
return toResponse((RollbackException) exception.getCause(), message); | ||
} | ||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), message).build(); | ||
} | ||
|
||
private Response toResponse(RollbackException exception, String message) { | ||
if (exception.getCause() instanceof PersistenceException) { | ||
return toResponse((PersistenceException) exception.getCause(), message); | ||
} | ||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), message).build(); | ||
} | ||
|
||
private Response toResponse(PersistenceException exception, String message) { | ||
if (exception.getCause() instanceof ConstraintViolationException) { | ||
return toResponse((ConstraintViolationException) exception.getCause(), message); | ||
} | ||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), message).build(); | ||
} | ||
|
||
private Response toResponse(ConstraintViolationException exception, String message) { | ||
return Response.status(Response.Status.CONFLICT.getStatusCode(), message).build(); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.