Search in sources :

Example 76 with ExceptionHandler

use of org.springframework.web.bind.annotation.ExceptionHandler in project skeleton-commons by skeleton-software-community.

the class RestExceptionHandler method handleException.

@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler(Exception.class)
@ResponseBody
public ErrorReport handleException(Exception e) {
    logger.error("exception thrown : " + e.getMessage(), e);
    ErrorReport errorReport = new ErrorReport();
    errorReport.setExceptionClassName(TechnicalError.class.getName());
    errorReport.setMessage(ApplicationException.ERROR_UNKNOWN);
    return errorReport;
}
Also used : ErrorReport(org.sklsft.commons.api.exception.ErrorReport) TechnicalError(org.sklsft.commons.api.exception.TechnicalError) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 77 with ExceptionHandler

use of org.springframework.web.bind.annotation.ExceptionHandler in project seldon-core by SeldonIO.

the class ExceptionControllerAdvice method handleUnauthorizedException.

@ExceptionHandler(SeldonAPIException.class)
public ResponseEntity<String> handleUnauthorizedException(SeldonAPIException exception) throws InvalidProtocolBufferException {
    Status.Builder statusBuilder = Status.newBuilder();
    statusBuilder.setCode(exception.getApiExceptionType().getId());
    statusBuilder.setReason(exception.getApiExceptionType().getMessage());
    statusBuilder.setInfo(exception.getInfo());
    statusBuilder.setStatus(Status.StatusFlag.FAILURE);
    Status status = statusBuilder.build();
    String json;
    json = ProtoBufUtils.toJson(status);
    return new ResponseEntity<String>(json, HttpStatus.valueOf(exception.getApiExceptionType().getHttpCode()));
}
Also used : HttpStatus(org.springframework.http.HttpStatus) Status(io.seldon.protos.PredictionProtos.Status) ResponseEntity(org.springframework.http.ResponseEntity) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler)

Example 78 with ExceptionHandler

use of org.springframework.web.bind.annotation.ExceptionHandler in project symmetric-ds by JumpMind.

the class RestService method handleError.

@ExceptionHandler(Exception.class)
@ResponseBody
public RestError handleError(Exception ex, HttpServletRequest req) {
    int httpErrorCode = 500;
    Annotation annotation = ex.getClass().getAnnotation(ResponseStatus.class);
    if (annotation != null) {
        httpErrorCode = ((ResponseStatus) annotation).value().value();
    }
    return new RestError(ex, httpErrorCode);
}
Also used : ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RestError(org.jumpmind.symmetric.web.rest.model.RestError) Annotation(java.lang.annotation.Annotation) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 79 with ExceptionHandler

use of org.springframework.web.bind.annotation.ExceptionHandler in project goci by EBISPOT.

the class ExceptionHandlerAdvice method handleResourceNotFound.

@ExceptionHandler(ResourceNotFoundException.class)
public ResponseEntity<ErrorResponse> handleResourceNotFound(ResourceNotFoundException ex, HttpServletRequest req) {
    ErrorResponse error = ErrorResponse.basicResponse(HttpStatus.NOT_FOUND, ex, req, dateFormat);
    log.error(error.toString());
    return new ResponseEntity<>(error, HttpStatus.NOT_FOUND);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ErrorResponse(uk.ac.ebi.spot.goci.curation.dto.ErrorResponse) ResponseEntityExceptionHandler(org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler)

Example 80 with ExceptionHandler

use of org.springframework.web.bind.annotation.ExceptionHandler in project pinpoint by naver.

the class ControllerExceptionHandler method defaultErrorHandler.

@ExceptionHandler(value = Exception.class)
public ModelAndView defaultErrorHandler(HttpServletRequest request, Exception exception) throws Exception {
    Objects.requireNonNull(request, "request");
    Objects.requireNonNull(exception, "exception");
    InternalServerError.RequestInfo requestInfo = createRequestResource(request);
    logger.warn("Failed to execute controller methods. message:{}, request:{}.", exception.getMessage(), requestInfo, exception);
    ModelAndView mav = new ModelAndView();
    InternalServerError error = createExceptionResource(requestInfo, exception);
    mav.addObject("exception", error);
    mav.setViewName(DEFAULT_ERROR_VIEW);
    mav.setStatus(HttpStatus.INTERNAL_SERVER_ERROR);
    return mav;
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) InternalServerError(com.navercorp.pinpoint.web.view.error.InternalServerError) 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