Commit 735b6e4e authored by Piotr Gawron's avatar Piotr Gawron
Browse files

removing default project returns 405 status code (NOT ALLOWED)

parent a44fffe2
......@@ -36,6 +36,8 @@ public abstract class BaseController {
return createErrorResponse("Object not found.", e.getMessage(), new HttpHeaders(), HttpStatus.NOT_FOUND);
} else if (e instanceof ObjectExistsException) {
return createErrorResponse("Object already exists.", e.getMessage(), new HttpHeaders(), HttpStatus.CONFLICT);
} else if (e instanceof OperationNotAllowedException) {
return createErrorResponse("Query server error.", e.getMessage(), new HttpHeaders(), HttpStatus.METHOD_NOT_ALLOWED);
} else if (e instanceof QueryException) {
logger.error(e, e);
return createErrorResponse("Query server error.", e.getMessage(), new HttpHeaders(), HttpStatus.BAD_REQUEST);
......
package lcsb.mapviewer.api;
/**
* Thrown when API operation is not allowed, but operation is valid. This can
* happen when user tries to remove default map.
*
* @author Piotr Gawron
*
*/
public class OperationNotAllowedException extends QueryException {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Default constructor.
*
* @param message
* error message
*/
public OperationNotAllowedException(String message) {
super(message);
}
/**
* Constructor with error message and parent exception.
*
* @param message
* error message
* @param reason
* parent exception that caused this one
*/
public OperationNotAllowedException(String message, Exception reason) {
super(message, reason);
}
}
......@@ -31,6 +31,7 @@ import org.springframework.util.MultiValueMap;
import lcsb.mapviewer.api.BaseRestImpl;
import lcsb.mapviewer.api.ObjectExistsException;
import lcsb.mapviewer.api.ObjectNotFoundException;
import lcsb.mapviewer.api.OperationNotAllowedException;
import lcsb.mapviewer.api.QueryException;
import lcsb.mapviewer.api.projects.models.publications.PublicationsRestImpl;
import lcsb.mapviewer.commands.ClearColorModelCommand;
......@@ -739,7 +740,7 @@ public class ProjectRestImpl extends BaseRestImpl {
throws SecurityException, QueryException {
Project project = getProjectService().getProjectByProjectId(projectId, token);
if (getConfigurationService().getConfigurationValue(ConfigurationElementType.DEFAULT_MAP).equals(project.getProjectId())) {
throw new QueryException("You cannot remove default map");
throw new OperationNotAllowedException("You cannot remove default map");
}
getProjectService().removeProject(project, path, true, token);
return getProject(projectId, token);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment