Search in sources :

Example 26 with ExceptionHandler

use of org.springframework.web.bind.annotation.ExceptionHandler in project Saturn by vipshop.

the class SaturnJobConsoleExceptionHandlerController method handleSaturnJobConsoleHttpException.

@ExceptionHandler
public ResponseEntity<Object> handleSaturnJobConsoleHttpException(SaturnJobConsoleHttpException e) {
    HttpHeaders httpHeaders = new HttpHeaders();
    SaturnJobConsoleHttpException saturnJobConsoleHttpException = (SaturnJobConsoleHttpException) e;
    int statusCode = saturnJobConsoleHttpException.getStatusCode();
    if (statusCode == HttpStatus.CREATED.value()) {
        return new ResponseEntity<>(httpHeaders, HttpStatus.CREATED);
    }
    return constructErrorResponse(e.getMessage(), HttpStatus.valueOf(statusCode));
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler)

Example 27 with ExceptionHandler

use of org.springframework.web.bind.annotation.ExceptionHandler in project Saturn by vipshop.

the class RestApiExceptionHandlerController method handleSaturnJobConsoleHttpException.

@ExceptionHandler
public ResponseEntity<Object> handleSaturnJobConsoleHttpException(SaturnJobConsoleHttpException e) {
    HttpHeaders httpHeaders = new HttpHeaders();
    SaturnJobConsoleHttpException saturnJobConsoleHttpException = (SaturnJobConsoleHttpException) e;
    int statusCode = saturnJobConsoleHttpException.getStatusCode();
    if (statusCode == HttpStatus.CREATED.value()) {
        return new ResponseEntity<>(httpHeaders, HttpStatus.CREATED);
    }
    return constructErrorResponse(e.getMessage(), HttpStatus.valueOf(statusCode));
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler)

Example 28 with ExceptionHandler

use of org.springframework.web.bind.annotation.ExceptionHandler in project transporter by wang4ever.

the class BasicTransportController method writeException.

/**
 * 输出异常信息
 *
 * @param t
 * @return
 */
@ExceptionHandler(value = Throwable.class)
private Object writeException(Throwable t) {
    JSONObject ret = new JSONObject();
    if (t instanceof IllegalAccessException)
        ret.put("code", "401");
    else
        ret.put("code", "500");
    ret.put("data", StringUtils.split(ExceptionUtils.getRootCauseMessage(t), ":")[1]);
    logger.error("Request error: {}", t);
    return ret;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler)

Example 29 with ExceptionHandler

use of org.springframework.web.bind.annotation.ExceptionHandler in project ArachneCentralAPI by OHDSI.

the class ExceptionHandlingController method exceptionHandler.

@ExceptionHandler(UserNotFoundException.class)
public ResponseEntity<JsonResult> exceptionHandler(UserNotFoundException ex, HttpServletResponse response) throws IOException {
    LOGGER.error(ex.getMessage(), ex);
    JsonResult result = new JsonResult<>(VALIDATION_ERROR);
    result.setErrorMessage(ex.getMessage());
    result.getValidatorErrors().put(ex.getField(), ex.getMessage());
    response.sendRedirect("/auth/login?message=email-not-confirmed");
    return new ResponseEntity<>(result, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler)

Example 30 with ExceptionHandler

use of org.springframework.web.bind.annotation.ExceptionHandler in project ArachneCentralAPI by OHDSI.

the class ExceptionHandlingController method exceptionHandler.

@ExceptionHandler(NotExistException.class)
public ResponseEntity<JsonResult> exceptionHandler(NotExistException ex) {
    LOGGER.error(ex.getMessage());
    JsonResult result = new JsonResult<>(VALIDATION_ERROR);
    result.setErrorMessage(ex.getMessage());
    result.getValidatorErrors().put(ex.getEntity().getSimpleName(), ex.getMessage());
    return new ResponseEntity<>(result, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) 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