Skip to content
This repository has been archived by the owner on Apr 8, 2019. It is now read-only.

Commit

Permalink
Add exception to specify bad input/data for a request/operation
Browse files Browse the repository at this point in the history
  • Loading branch information
nscavell committed Apr 1, 2013
1 parent 666e25a commit a307dad
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
@@ -0,0 +1,17 @@
package org.gatein.management.api.exceptions;

/**
* @author <a href="mailto:nscavell@redhat.com">Nick Scavelli</a>
*/
public class InvalidDataException extends ManagementException
{
public InvalidDataException(final String message)
{
super(message);
}

public InvalidDataException(final String message, final Throwable cause)
{
super(message, cause);
}
}
Expand Up @@ -35,6 +35,7 @@
import org.gatein.management.api.annotations.MappedAttribute;
import org.gatein.management.api.annotations.MappedPath;
import org.gatein.management.api.binding.Marshaller;
import org.gatein.management.api.exceptions.InvalidDataException;
import org.gatein.management.api.exceptions.NotAuthorizedException;
import org.gatein.management.api.exceptions.OperationException;
import org.gatein.management.api.exceptions.ResourceNotFoundException;
Expand Down Expand Up @@ -213,6 +214,10 @@ else if (e.getCause() instanceof OperationException)
{
throw (OperationException) e.getCause();
}
else if (e.getCause() instanceof InvalidDataException)
{
throw (InvalidDataException) e.getCause();
}
throw new RuntimeException("Could not invoke method " + this.method + " on object " + instance, e);
}
}
Expand Down
Expand Up @@ -28,6 +28,7 @@
import org.gatein.management.api.PathAddress;
import org.gatein.management.api.controller.ManagedResponse;
import org.gatein.management.api.controller.ManagementController;
import org.gatein.management.api.exceptions.InvalidDataException;
import org.gatein.management.api.exceptions.NotAuthorizedException;
import org.gatein.management.api.exceptions.OperationException;
import org.gatein.management.api.exceptions.ResourceNotFoundException;
Expand Down Expand Up @@ -442,6 +443,13 @@ private Response executeRequest(UriInfo uriInfo, HttpManagedRequest request)
return failure(e.getMessage(), operationName, Status.INTERNAL_SERVER_ERROR, contentType);
}
}
catch (InvalidDataException e)
{
if (log.isDebugEnabled()) {
log.error("Bad request for address " + address + " and operation " + operationName, e);
}
return failure(e.getMessage(), operationName, Status.BAD_REQUEST, contentType);
}
catch (Exception e)
{
String message = "Error processing operation: " + operationName + ", address: " + address + ", content-type: " + contentType;
Expand Down

0 comments on commit a307dad

Please sign in to comment.