Search in sources :

Example 1 with RestError

use of org.entando.entando.web.common.model.RestError in project entando-core by entando.

the class RestExceptionHandler method processRestRourceNotFoundEx.

@ExceptionHandler(value = RestRourceNotFoundException.class)
@ResponseStatus(HttpStatus.NOT_FOUND)
@ResponseBody
public RestResponse processRestRourceNotFoundEx(RestRourceNotFoundException ex) {
    logger.debug("Handling {} error", ex.getClass().getSimpleName());
    RestResponse response = null;
    if (null != ex.getBindingResult()) {
        BindingResult result = ex.getBindingResult();
        response = processAllErrors(result);
    } else {
        response = new RestResponse();
        RestError error = new RestError(ex.getErrorCode(), this.resolveLocalizedErrorMessage("NOT_FOUND", new Object[] { ex.getObjectName(), ex.getObjectCode() }));
        List<RestError> errors = new ArrayList<>();
        errors.add(error);
        response.setErrors(errors);
        response.setMetaData(new HashMap<>());
    }
    return response;
}
Also used : BindingResult(org.springframework.validation.BindingResult) RestResponse(org.entando.entando.web.common.model.RestResponse) RestError(org.entando.entando.web.common.model.RestError) ArrayList(java.util.ArrayList) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with RestError

use of org.entando.entando.web.common.model.RestError in project entando-core by entando.

the class RestExceptionHandler method processGlobalErrors.

private RestResponse processGlobalErrors(RestResponse dto, List<ObjectError> globalErrors) {
    if (null != globalErrors) {
        List<RestError> errors = new ArrayList<>();
        for (ObjectError globalError : globalErrors) {
            String localizedErrorMessage = resolveLocalizedErrorMessage(globalError);
            errors.add(new RestError(globalError.getCode(), localizedErrorMessage));
        }
        dto.addErrors(errors);
    }
    return dto;
}
Also used : ObjectError(org.springframework.validation.ObjectError) RestError(org.entando.entando.web.common.model.RestError) ArrayList(java.util.ArrayList)

Example 3 with RestError

use of org.entando.entando.web.common.model.RestError in project entando-core by entando.

the class RestExceptionHandler method processEntandoTokenException.

@ExceptionHandler(value = EntandoTokenException.class)
@ResponseStatus(HttpStatus.FORBIDDEN)
@ResponseBody
public RestResponse processEntandoTokenException(EntandoAuthorizationException ex) {
    logger.debug("Handling {} error", ex.getClass().getSimpleName());
    RestResponse response = new RestResponse();
    RestError error = new RestError(RestErrorCodes.UNAUTHORIZED, this.resolveLocalizedErrorMessage("UNAUTHORIZED", new Object[] { ex.getUsername(), ex.getRequestURI(), ex.getMethod() }));
    List<RestError> errors = new ArrayList<>();
    errors.add(error);
    response.setErrors(errors);
    return response;
}
Also used : RestResponse(org.entando.entando.web.common.model.RestResponse) RestError(org.entando.entando.web.common.model.RestError) ArrayList(java.util.ArrayList) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with RestError

use of org.entando.entando.web.common.model.RestError in project entando-core by entando.

the class RestExceptionHandler method processEntandoAuthorizationException.

@ExceptionHandler(value = EntandoAuthorizationException.class)
@ResponseStatus(HttpStatus.UNAUTHORIZED)
@ResponseBody
public RestResponse processEntandoAuthorizationException(EntandoAuthorizationException ex) {
    logger.debug("Handling {} error", ex.getClass().getSimpleName());
    RestResponse response = new RestResponse();
    RestError error = new RestError(RestErrorCodes.UNAUTHORIZED, this.resolveLocalizedErrorMessage("UNAUTHORIZED", new Object[] { ex.getUsername(), ex.getRequestURI(), ex.getMethod() }));
    List<RestError> errors = new ArrayList<>();
    errors.add(error);
    response.setErrors(errors);
    return response;
}
Also used : RestResponse(org.entando.entando.web.common.model.RestResponse) RestError(org.entando.entando.web.common.model.RestError) ArrayList(java.util.ArrayList) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 5 with RestError

use of org.entando.entando.web.common.model.RestError in project entando-core by entando.

the class RestExceptionHandler method processFieldErrors.

private RestResponse processFieldErrors(RestResponse dto, List<FieldError> fieldErrors) {
    if (null != fieldErrors) {
        List<RestError> errors = new ArrayList<>();
        for (FieldError fieldError : fieldErrors) {
            String localizedErrorMessage = resolveLocalizedErrorMessage(fieldError);
            errors.add(new RestError(fieldError.getCode(), localizedErrorMessage));
        }
        dto.addErrors(errors);
    }
    return dto;
}
Also used : RestError(org.entando.entando.web.common.model.RestError) ArrayList(java.util.ArrayList) FieldError(org.springframework.validation.FieldError)

Aggregations

ArrayList (java.util.ArrayList)6 RestError (org.entando.entando.web.common.model.RestError)6 RestResponse (org.entando.entando.web.common.model.RestResponse)4 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)4 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)4 BindingResult (org.springframework.validation.BindingResult)1 FieldError (org.springframework.validation.FieldError)1 ObjectError (org.springframework.validation.ObjectError)1