com.gitlab.oliverlj.jsonapi.configuration.JsonApiResponseEntityExceptionHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spring-boot-starter-json-api Show documentation
Show all versions of spring-boot-starter-json-api Show documentation
A spring boot starter which brings json api converter (https://github.com/jasminb/jsonapi-converter) for your great spring project
The newest version!
package com.gitlab.oliverlj.jsonapi.configuration;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import javax.validation.ConstraintViolationException;
import org.eclipse.jdt.annotation.Nullable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.server.ResponseStatusException;
import org.springframework.web.util.WebUtils;
import com.github.jasminb.jsonapi.JSONAPIDocument;
import com.github.jasminb.jsonapi.JSONAPISpecConstants;
import com.github.jasminb.jsonapi.models.errors.Error;
import com.github.jasminb.jsonapi.models.errors.Source;
import com.gitlab.oliverlj.jsonapi.configuration.converters.ConstraintViolationConverter;
import com.gitlab.oliverlj.jsonapi.configuration.converters.ErrorConverter;
import com.gitlab.oliverlj.jsonapi.exceptions.UnprocessableEntityException;
/**
* A response entity exception handler for request which accepts {@code application/vnd.api+json}
* that wish to provide centralized exception handling across all {@code @RequestMapping} methods.
*
* @author Olivier LE JACQUES ([email protected])
*
*/
@ControllerAdvice
@ComponentScan(basePackageClasses = ErrorConverter.class)
public class JsonApiResponseEntityExceptionHandler {
@Autowired
private ConstraintViolationConverter constraintViolationConverter;
@ExceptionHandler(value = {ResponseStatusException.class})
protected ResponseEntity
© 2015 - 2025 Weber Informatics LLC | Privacy Policy