Commit f29a9051 authored by Matija Obreza's avatar Matija Obreza
Browse files

Merge branch '159-maxpagelimitexception-log' into 'master'

MaxPageLimitException log

Closes #159

See merge request !75
parents 99276fc6 c353915c
......@@ -22,17 +22,25 @@ package org.genesys2.server.exception;
public class MaxPageLimitException extends RuntimeException {
private static final long serialVersionUID = -8667874524883066239L;
private Integer maxPageLimit;
private Integer requestedPageSize;
public MaxPageLimitException(final Integer maxPageLimit) {
public MaxPageLimitException(final Integer maxPageLimit, final Integer requestedPageSize) {
this.maxPageLimit = maxPageLimit;
this.requestedPageSize = requestedPageSize;
}
@Override
public String getMessage() {
return "Genesys does not support requests for data beyond " + maxPageLimit + "th page.";
final StringBuilder stringBuilder = new StringBuilder();
return stringBuilder.append("Genesys does not support requests for data beyond ").append(maxPageLimit)
.append("th page. Requested page was ").append(requestedPageSize).append(".").toString();
}
public Integer getMaxPageLimit() {
return maxPageLimit;
}
public Integer getRequestedPageSize() {
return requestedPageSize;
}
}
......@@ -167,7 +167,7 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
transformFiltersIfNeed(filters);
if (pageable.getPageNumber() > PAGINATION_MAXPAGE_LIMIT) {
throw new MaxPageLimitException(PAGINATION_MAXPAGE_LIMIT);
throw new MaxPageLimitException(PAGINATION_MAXPAGE_LIMIT, pageable.getPageNumber() + 1);
}
final DirectMysqlQuery directQuery = new DirectMysqlQuery("accession", "a");
......
......@@ -23,6 +23,7 @@ import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.genesys2.server.exception.MaxPageLimitException;
import org.genesys2.spring.ResourceNotFoundException;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
......@@ -74,6 +75,15 @@ public class UserControllerAdvice extends BaseController {
return mav;
}
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(value = { MaxPageLimitException.class })
public ModelAndView handleMaxPageLimitException(final MaxPageLimitException e) {
_logger.error(e.getMessage());
final ModelAndView mav = new ModelAndView("/errors/error");
mav.addObject("exception", e);
return mav;
}
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler(value = { Throwable.class })
public ModelAndView handleAll(final HttpServletRequest req, final Throwable e) {
......
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