ensure all exception mappers return JSON (can revert to html/text if resource allows that format
This commit is contained in:
+2
-1
@@ -1,5 +1,6 @@
|
||||
package org.mifosng.platform.api.errorhandling;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
import javax.ws.rs.ext.ExceptionMapper;
|
||||
@@ -24,6 +25,6 @@ public class AccessDeniedExceptionMapper implements ExceptionMapper<AccessDenied
|
||||
@Override
|
||||
public Response toResponse(AccessDeniedException exception) {
|
||||
// Status code 403 really reads as: "Authenticated - but not authorized":
|
||||
return Response.status(Status.FORBIDDEN).entity(ApiGlobalErrorResponse.unAuthorized()).build();
|
||||
return Response.status(Status.FORBIDDEN).entity(ApiGlobalErrorResponse.unAuthorized()).type(MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
package org.mifosng.platform.api.errorhandling;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
import javax.ws.rs.ext.ExceptionMapper;
|
||||
@@ -22,6 +23,6 @@ public class BadCredentialsExceptionMapper implements ExceptionMapper<BadCredent
|
||||
|
||||
@Override
|
||||
public Response toResponse(BadCredentialsException exception) {
|
||||
return Response.status(Status.UNAUTHORIZED).entity(ApiGlobalErrorResponse.unAuthenticated()).build();
|
||||
return Response.status(Status.UNAUTHORIZED).entity(ApiGlobalErrorResponse.unAuthenticated()).type(MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
package org.mifosng.platform.api.errorhandling;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
import javax.ws.rs.ext.ExceptionMapper;
|
||||
@@ -24,6 +25,6 @@ public class NoAuthorizationExceptionMapper implements ExceptionMapper<NoAuthori
|
||||
@Override
|
||||
public Response toResponse(NoAuthorizationException exception) {
|
||||
// Status code 403 really reads as: "Authenticated - but not authorized":
|
||||
return Response.status(Status.FORBIDDEN).entity(ApiGlobalErrorResponse.unAuthorized()).build();
|
||||
return Response.status(Status.FORBIDDEN).entity(ApiGlobalErrorResponse.unAuthorized()).type(MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
package org.mifosng.platform.api.errorhandling;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
import javax.ws.rs.ext.ExceptionMapper;
|
||||
@@ -26,6 +27,6 @@ public class PlatformApiDataValidationExceptionMapper implements ExceptionMapper
|
||||
ApiGlobalErrorResponse dataIntegrityError = ApiGlobalErrorResponse.badClientRequest(exception.getGlobalisationMessageCode(),
|
||||
exception.getDefaultUserMessage(), exception.getErrors());
|
||||
|
||||
return Response.status(Status.BAD_REQUEST).entity(dataIntegrityError).build();
|
||||
return Response.status(Status.BAD_REQUEST).entity(dataIntegrityError).type(MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
package org.mifosng.platform.api.errorhandling;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
import javax.ws.rs.ext.ExceptionMapper;
|
||||
@@ -25,6 +26,6 @@ public class PlatformDomainRuleExceptionMapper implements ExceptionMapper<Abstra
|
||||
|
||||
ApiGlobalErrorResponse notFoundErrorResponse = ApiGlobalErrorResponse.domainRuleViolation(exception.getGlobalisationMessageCode(), exception.getDefaultUserMessage(), exception.getDefaultUserMessageArgs());
|
||||
// request understood but not carried out due to it violating some domain/business logic
|
||||
return Response.status(Status.FORBIDDEN).entity(notFoundErrorResponse).build();
|
||||
return Response.status(Status.FORBIDDEN).entity(notFoundErrorResponse).type(MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
package org.mifosng.platform.api.errorhandling;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
import javax.ws.rs.ext.ExceptionMapper;
|
||||
@@ -24,6 +25,6 @@ public class PlatformInternalServerExceptionMapper implements ExceptionMapper<Pl
|
||||
public Response toResponse(PlatformInternalServerException exception) {
|
||||
|
||||
ApiGlobalErrorResponse notFoundErrorResponse = ApiGlobalErrorResponse.notFound(exception.getGlobalisationMessageCode(), exception.getDefaultUserMessage(), exception.getDefaultUserMessageArgs());
|
||||
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(notFoundErrorResponse).build();
|
||||
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(notFoundErrorResponse).type(MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
package org.mifosng.platform.api.errorhandling;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
import javax.ws.rs.ext.ExceptionMapper;
|
||||
@@ -24,6 +25,6 @@ public class PlatformResourceNotFoundExceptionMapper implements ExceptionMapper<
|
||||
public Response toResponse(AbstractPlatformResourceNotFoundException exception) {
|
||||
|
||||
ApiGlobalErrorResponse notFoundErrorResponse = ApiGlobalErrorResponse.notFound(exception.getGlobalisationMessageCode(), exception.getDefaultUserMessage(), exception.getDefaultUserMessageArgs());
|
||||
return Response.status(Status.NOT_FOUND).entity(notFoundErrorResponse).build();
|
||||
return Response.status(Status.NOT_FOUND).entity(notFoundErrorResponse).type(MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
package org.mifosng.platform.api.errorhandling;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
import javax.ws.rs.ext.ExceptionMapper;
|
||||
@@ -21,6 +22,6 @@ public class UnAuthenticatedUserExceptionMapper implements ExceptionMapper<UnAut
|
||||
@Override
|
||||
public Response toResponse(UnAuthenticatedUserException exception) {
|
||||
// Status code 401 really reads as: "Unauthenticated":
|
||||
return Response.status(Status.UNAUTHORIZED).entity(ApiGlobalErrorResponse.unAuthenticated()).build();
|
||||
return Response.status(Status.UNAUTHORIZED).entity(ApiGlobalErrorResponse.unAuthenticated()).type(MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -3,6 +3,7 @@ package org.mifosng.platform.api.errorhandling;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
import javax.ws.rs.ext.ExceptionMapper;
|
||||
@@ -40,6 +41,6 @@ public class UnrecognizedPropertyExceptionMapper implements ExceptionMapper<Unre
|
||||
"validation.msg.validation.errors.exist",
|
||||
"Validation errors exist.", errors);
|
||||
|
||||
return Response.status(Status.BAD_REQUEST).entity(invalidParameterError).build();
|
||||
return Response.status(Status.BAD_REQUEST).entity(invalidParameterError).type(MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -3,6 +3,7 @@ package org.mifosng.platform.api.errorhandling;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
import javax.ws.rs.ext.ExceptionMapper;
|
||||
@@ -42,6 +43,6 @@ public class UnrecognizedQueryParamExceptionMapper implements ExceptionMapper<Un
|
||||
"validation.msg.validation.errors.exist",
|
||||
"Validation errors exist.", errors);
|
||||
|
||||
return Response.status(Status.BAD_REQUEST).entity(invalidParameterError).build();
|
||||
return Response.status(Status.BAD_REQUEST).entity(invalidParameterError).type(MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user