Search in sources :

Example 11 with BodyBuilder

use of org.springframework.http.ResponseEntity.BodyBuilder in project tutorials by eugenp.

the class ExceptionTranslator method processRuntimeException.

@ExceptionHandler(Exception.class)
public ResponseEntity<ErrorVM> processRuntimeException(Exception ex) {
    BodyBuilder builder;
    ErrorVM errorVM;
    ResponseStatus responseStatus = AnnotationUtils.findAnnotation(ex.getClass(), ResponseStatus.class);
    if (responseStatus != null) {
        builder = ResponseEntity.status(responseStatus.value());
        errorVM = new ErrorVM("error." + responseStatus.value().value(), responseStatus.reason());
    } else {
        builder = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR);
        errorVM = new ErrorVM(ErrorConstants.ERR_INTERNAL_SERVER_ERROR, "Internal server error");
    }
    return builder.body(errorVM);
}
Also used : BodyBuilder(org.springframework.http.ResponseEntity.BodyBuilder)

Aggregations

BodyBuilder (org.springframework.http.ResponseEntity.BodyBuilder)11 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)5 IdmAttachmentDto (eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto)5 IOException (java.io.IOException)5 InputStream (java.io.InputStream)5 InputStreamResource (org.springframework.core.io.InputStreamResource)5 ApiOperation (io.swagger.annotations.ApiOperation)3 ResponseEntity (org.springframework.http.ResponseEntity)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 UUID (java.util.UUID)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 IdmProfileDto (eu.bcvsolutions.idm.core.api.dto.IdmProfileDto)1 EntityNotFoundException (eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException)1 IdmNotificationAttachmentDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationAttachmentDto)1 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)1