Commit 112725df authored by oleg.pahhomov's avatar oleg.pahhomov

SA0140-531 | data integrity errors are remapped

parent 1a99ff79
package ee.stat.dashboard.controller;
import ee.stat.dashboard.util.StatBadRequestException;
import org.springframework.context.annotation.Profile;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
......@@ -14,17 +14,17 @@ public class ErrorHandler {
@ExceptionHandler(StatBadRequestException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ExceptionResponse handleStatDbBadRequest(StatBadRequestException ce) {
public ExceptionResponse handleStatDbBadRequest(StatBadRequestException ex) {
ExceptionResponse response = new ExceptionResponse();
response.setCode(ce.getCode());
response.setMessage(ce.getMessage());
response.setLocalizedMessage(ce.getLocalizedMessage());
response.setCode(ex.getCode());
response.setMessage(ex.getMessage());
response.setLocalizedMessage(ex.getLocalizedMessage());
response.setHttpStatus(HttpStatus.BAD_REQUEST.value());
response.setTimestamp(OffsetDateTime.now());
return response;
}
@ExceptionHandler(RuntimeException.class)
@ExceptionHandler(DataIntegrityViolationException.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public ExceptionResponse handleInternalError(RuntimeException ce) {
ExceptionResponse response = new ExceptionResponse();
......
......@@ -33,7 +33,6 @@ public class DashboardWidgetController {
private WidgetService widgetService;
private WidgetSaveService widgetSaveService;
private DashboardRepository dashboardRepository;
@GetMapping(path = "/widget/{widgetId}")
public Response<WidgetResponse> findById(@PathVariable Long dashboardId,
......
......@@ -17,10 +17,6 @@ public class ResponseUtil {
return () -> badRequestException(item, reason);
}
public static Supplier<ResponseStatusException> missing(Long id, String item) {
return () -> notFoundException(id, item);
}
private static ResponseStatusException badRequestException(Long id, String item) {
return new ResponseStatusException(HttpStatus.BAD_REQUEST, format("%s does not exist, id: %s", item, id));
}
......@@ -28,8 +24,4 @@ public class ResponseUtil {
private static ResponseStatusException badRequestException(String item, String reason) {
return new ResponseStatusException(HttpStatus.BAD_REQUEST, format("Problem with %s, reason: %s", item, reason));
}
private static ResponseStatusException notFoundException(Long id, String item) {
return new ResponseStatusException(HttpStatus.NOT_FOUND, format("%s does not exist, id: %s", item, id));
}
}
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