Commit 09848158 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

error handling added

parent 959a9347
......@@ -17,7 +17,7 @@ public abstract class BaseController {
return new ResponseEntity<Object>("{\"error\" : \"Access denied.\",\"reason\":\"" + e.getMessage() + "\"}", new HttpHeaders(), HttpStatus.FORBIDDEN);
} else if (e instanceof QueryException) {
return new ResponseEntity<Object>(
"{\"error\" : \"Query server error.\",\"reason\":\"" + e.getMessage() + "\"}", new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR);
"{\"error\" : \"Query server error.\",\"reason\":\"" + e.getMessage() + "\"}", new HttpHeaders(), HttpStatus.BAD_REQUEST);
} else {
return new ResponseEntity<Object>(
"{\"error\" : \"Internal server error.\",\"reason\":\"" + e.getMessage() + "\"}", new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR);
......
......@@ -9,8 +9,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import lcsb.mapviewer.api.QueryException;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.cache.FileEntry;
import lcsb.mapviewer.model.map.layout.Layout;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.services.SecurityException;
import lcsb.mapviewer.services.interfaces.ILayoutService;
......@@ -135,7 +135,16 @@ public class OverlayRestImpl {
if (model == null) {
throw new QueryException("Project with given id doesn't exist");
}
return layoutService.getLayoutDataById(Integer.valueOf(overlayId), authenticationToken).getInputData();
try {
Integer id = Integer.valueOf(overlayId);
Layout layout = layoutService.getLayoutDataById(id, authenticationToken);
if (layout == null) {
throw new QueryException("Invalid overlay id");
}
return layout.getInputData();
} catch (NumberFormatException e) {
throw new QueryException("Invalid overlay id");
}
}
}
......@@ -917,6 +917,9 @@ public class LayoutService implements ILayoutService {
private Layout getLayoutById(int layoutId, AuthenticationToken token) throws SecurityException {
Layout layout = layoutDao.getById(layoutId);
if (layout == null) {
return null;
}
User user = userService.getUserByToken(token);
if (!userCanViewOverlay(layout, user)) {
throw new SecurityException("User doesn't have access to overlay");
......
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