io.elsci.signals.mock.exception.RestExceptionHandler Maven / Gradle / Ivy
package io.elsci.signals.mock.exception;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
import static org.springframework.http.HttpStatus.NOT_FOUND;
@ControllerAdvice
@ResponseBody
class RestExceptionHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(RestExceptionHandler.class);
@ExceptionHandler({ EntityNotFoundException.class })
@ResponseStatus(NOT_FOUND)
String handleEntityNotException(EntityNotFoundException ex) {
//can't return an object because it's possible that the client's Accept was bytes or image,
// and thus it won't be able to convert the object to the requested type
return ex.getMessage();
}
@ExceptionHandler({ Throwable.class })
@ResponseStatus(INTERNAL_SERVER_ERROR)
String handleOthers(Throwable ex) {
LOGGER.error("Couldn't handle request", ex);
return ex.getMessage();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy