Search in sources :

Example 56 with ExceptionHandler

use of org.springframework.web.bind.annotation.ExceptionHandler in project irida by phac-nml.

the class ExceptionHandlerController method handleAccessDeniedException.

/**
 * Handle an {@link AccessDeniedException} and return an Http 403
 *
 * @param ex
 *            The caught {@link AccessDeniedException}
 * @return name of the access denied view
 */
@ExceptionHandler(AccessDeniedException.class)
@ResponseStatus(HttpStatus.FORBIDDEN)
public ModelAndView handleAccessDeniedException(AccessDeniedException ex) {
    logger.error(ex.getMessage(), ex);
    ModelAndView modelAndView = new ModelAndView(ACCESS_DENIED_PAGE);
    modelAndView.addObject("adminEmail", adminEmail);
    return modelAndView;
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

Example 57 with ExceptionHandler

use of org.springframework.web.bind.annotation.ExceptionHandler in project irida by phac-nml.

the class ExceptionHandlerController method handleOAuthProblemException.

/**
 * Catch an {@link OAuthProblemException} and return an http 500 error
 *
 * @param ex
 *            the caught {@link OAuthProblemException}
 * @return A {@link ModelAndView} containing the name of the oauth error
 *         view
 */
@ExceptionHandler(OAuthProblemException.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public ModelAndView handleOAuthProblemException(OAuthProblemException ex) {
    logger.error("OAuth exception: " + ex.getMessage(), ex);
    ModelAndView modelAndView = new ModelAndView(OAUTH_ERROR_PAGE);
    modelAndView.addObject("exception", ex);
    modelAndView.addObject("adminEmail", adminEmail);
    return modelAndView;
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

Example 58 with ExceptionHandler

use of org.springframework.web.bind.annotation.ExceptionHandler in project irida by phac-nml.

the class ExceptionHandlerController method handleIOException.

/**
 * Catch and handle {@link IOException}s. Render an error that's just a
 * general storage exception.
 *
 * @param e
 *            the exception that was originally thrown.
 * @param locale
 *            the locale of the request.
 * @return an error message for general storage exceptions.
 */
@ExceptionHandler(IOException.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public ModelMap handleIOException(final IOException e, final Locale locale) {
    logger.error("Error writing sequence file", e);
    final ModelMap modelMap = new ModelMap();
    modelMap.addAttribute("error_message", messageSource.getMessage("project.samples.files.upload.error.storageexception", null, locale));
    return modelMap;
}
Also used : ModelMap(org.springframework.ui.ModelMap) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

Example 59 with ExceptionHandler

use of org.springframework.web.bind.annotation.ExceptionHandler in project irida by phac-nml.

the class ControllerExceptionHandler method handleInvalidPropertyException.

/**
 * Handle
 * {@link ca.corefacility.bioinformatics.irida.exceptions.InvalidPropertyException}
 * .
 *
 * @param e
 *            the exception as thrown by the service.
 * @return an appropriate HTTP response.
 */
@ExceptionHandler(InvalidPropertyException.class)
public ResponseEntity<ErrorResponse> handleInvalidPropertyException(InvalidPropertyException e) {
    logger.error("A client attempted to update a resource with an" + " invalid property at " + new Date() + ". The stack trace follows: ", e);
    ErrorResponse errorResponse;
    Class<? extends Object> affectedClass = e.getAffectedClass();
    if (affectedClass != null) {
        List<String> properties = getProperties(affectedClass);
        String message = "Cannot update resource with supplied properties.";
        errorResponse = new ErrorResponse(message);
        errorResponse.addProperty("available-properties", properties);
    } else {
        String message = "Cannot update resource with supplied properties: " + e.getMessage();
        errorResponse = new ErrorResponse(message);
    }
    return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) Date(java.util.Date) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler)

Example 60 with ExceptionHandler

use of org.springframework.web.bind.annotation.ExceptionHandler in project nzbhydra2 by theotherp.

the class NewsWeb method handleNewsException.

@ExceptionHandler(value = { IOException.class })
protected ResponseEntity<ExceptionInfo> handleNewsException(IOException ex, WebRequest request) {
    String error = "An error occurred while getting news: " + ex.getMessage();
    logger.error(error);
    return new ResponseEntity<>(new ExceptionInfo(500, error, ex.getClass().getName(), error, request.getContextPath()), HttpStatus.valueOf(500));
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ExceptionInfo(org.nzbhydra.ExceptionInfo) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler)

Aggregations

ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)178 ResponseEntity (org.springframework.http.ResponseEntity)58 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)48 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)41 HttpHeaders (org.springframework.http.HttpHeaders)39 ModelAndView (org.springframework.web.servlet.ModelAndView)33 ResponseEntityExceptionHandler (org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler)31 JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)17 HttpStatus (org.springframework.http.HttpStatus)13 AjaxJson (com.cdeledu.common.base.AjaxJson)12 ResultModels (eu.bcvsolutions.idm.core.api.dto.ResultModels)8 DefaultErrorModel (eu.bcvsolutions.idm.core.api.exception.DefaultErrorModel)8 ErrorModel (eu.bcvsolutions.idm.core.api.exception.ErrorModel)8 RestResponse (org.entando.entando.web.common.model.RestResponse)8 ArrayList (java.util.ArrayList)7 BindingResult (org.springframework.validation.BindingResult)6 FieldError (org.springframework.validation.FieldError)5 ErrorInfo (com.haulmont.restapi.exception.ErrorInfo)4 PrintWriter (java.io.PrintWriter)4 StringWriter (java.io.StringWriter)4