[Minor] Code cleanup
This commit is contained in:
parent
c6badc27cf
commit
9282773e4b
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue