[Minor] Code cleanup

This commit is contained in:
Robert von Burg 2023-04-06 07:54:08 +02:00
parent c6badc27cf
commit 9282773e4b
Signed by: eitch
GPG Key ID: 75DB9C85C74331F7
2 changed files with 4 additions and 7 deletions

View File

@ -21,6 +21,7 @@ import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.Response.Status;
import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider;
import java.text.MessageFormat;
import li.strolch.exception.StrolchAccessDeniedException;
@ -42,13 +43,10 @@ public class StrolchRestfulExceptionMapper implements ExceptionMapper<Exception>
if (ex instanceof NotFoundException)
return ResponseUtil.toResponse(Status.NOT_FOUND, ex);
if (ex instanceof StrolchAccessDeniedException) {
StrolchAccessDeniedException e = (StrolchAccessDeniedException) ex;
if (ex instanceof StrolchAccessDeniedException e)
return ResponseUtil.toResponse(Status.FORBIDDEN, e.getI18n());
}
if (ex instanceof StrolchNotAuthenticatedException) {
StrolchNotAuthenticatedException e = (StrolchNotAuthenticatedException) ex;
if (ex instanceof StrolchNotAuthenticatedException e) {
logger.error("User tried to access resource, but was not authenticated: " + ex.getMessage());
return Response.status(Status.UNAUTHORIZED).entity(e.getMessage()).type(MediaType.TEXT_PLAIN).build();
}

View File

@ -179,8 +179,7 @@ public class ResponseUtil {
public static Response toResponse(Status status, Throwable t) {
JsonObject response = new JsonObject();
if (t instanceof StrolchUserMessageException && ((StrolchUserMessageException) t).hasI18n()) {
StrolchUserMessageException ex = (StrolchUserMessageException) t;
if (t instanceof StrolchUserMessageException ex && ((StrolchUserMessageException) t).hasI18n()) {
response.add("i18n", ex.getI18n().accept(new I18nMessageToJsonVisitor()));
} else {
Throwable rootCause = getRootCause(t);