Search in sources :

Example 91 with RestResponse

use of org.entando.entando.web.common.model.RestResponse 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 92 with RestResponse

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

the class RestExceptionHandler method processValidationError.

@ExceptionHandler(value = MethodArgumentNotValidException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody
public RestResponse processValidationError(MethodArgumentNotValidException ex) {
    logger.debug("Handling {} error", ex.getClass().getSimpleName());
    BindingResult result = ex.getBindingResult();
    RestResponse response = processAllErrors(result);
    return response;
}
Also used : BindingResult(org.springframework.validation.BindingResult) RestResponse(org.entando.entando.web.common.model.RestResponse) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 93 with RestResponse

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

the class RestExceptionHandler method processAllErrors.

private RestResponse processAllErrors(List<FieldError> fieldErrors, List<ObjectError> objectErrors) {
    RestResponse dto = new RestResponse();
    processFieldErrors(dto, fieldErrors);
    processGlobalErrors(dto, objectErrors);
    return dto;
}
Also used : RestResponse(org.entando.entando.web.common.model.RestResponse)

Example 94 with RestResponse

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

the class RestExceptionHandler method processRuntimeExceptionException.

@ExceptionHandler(value = RuntimeException.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ResponseBody
public RestResponse processRuntimeExceptionException(RuntimeException ex) {
    logger.debug("Handling {} error", ex.getClass().getSimpleName());
    RestResponse response = new RestResponse();
    RestError error = new RestError(RestErrorCodes.INTERNAL_ERROR, this.resolveLocalizedErrorMessage("GENERIC_ERROR", new Object[] { ex.getMessage() }));
    List<RestError> errors = new ArrayList<>();
    errors.add(error);
    response.setErrors(errors);
    ex.printStackTrace();
    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 95 with RestResponse

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

the class RestExceptionHandler method processValidationError.

@ExceptionHandler(value = ValidationConflictException.class)
@ResponseStatus(HttpStatus.CONFLICT)
@ResponseBody
public RestResponse processValidationError(ValidationConflictException ex) {
    logger.debug("Handling {} error", ex.getClass().getSimpleName());
    BindingResult result = ex.getBindingResult();
    RestResponse response = processAllErrors(result);
    return response;
}
Also used : BindingResult(org.springframework.validation.BindingResult) RestResponse(org.entando.entando.web.common.model.RestResponse) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

RestResponse (org.entando.entando.web.common.model.RestResponse)95 RestAccessControl (org.entando.entando.web.common.annotation.RestAccessControl)86 ResponseEntity (org.springframework.http.ResponseEntity)86 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)86 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)34 HashMap (java.util.HashMap)33 ArrayList (java.util.ArrayList)18 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)8 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)8 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)8 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)8 PageDto (org.entando.entando.aps.system.services.page.model.PageDto)7 BindingResult (org.springframework.validation.BindingResult)7 UserDto (org.entando.entando.aps.system.services.user.model.UserDto)6 ValidationConflictException (org.entando.entando.web.common.exceptions.ValidationConflictException)5 CategoryDto (org.entando.entando.aps.system.services.category.model.CategoryDto)4 DataModelDto (org.entando.entando.aps.system.services.dataobjectmodel.model.DataModelDto)4 LabelDto (org.entando.entando.aps.system.services.label.model.LabelDto)4 RoleDto (org.entando.entando.aps.system.services.role.model.RoleDto)4 WidgetDto (org.entando.entando.aps.system.services.widgettype.model.WidgetDto)4