Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.accessgatelabs.oss.builder.exceptions;
import static org.springframework.http.HttpStatus.BAD_REQUEST;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.http.converter.HttpMessageNotWritableException;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.HttpMediaTypeNotSupportedException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.context.request.ServletWebRequest;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
import org.springframework.web.multipart.MaxUploadSizeExceededException;
import org.springframework.web.multipart.MultipartException;
import org.springframework.web.servlet.HandlerMapping;
import org.springframework.web.servlet.NoHandlerFoundException;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.accessgatelabs.oss.builder.models.ApiServiceResponse;
import com.accessgatelabs.oss.builder.models.ExceptionResponseBuilder;
import com.accessgatelabs.oss.builder.models.HttpResponse;
import com.accessgatelabs.oss.builder.models.ServiceResponse;
import com.accessgatelabs.oss.builder.models.StateServiceResponse;
import com.accessgatelabs.oss.builder.models.ViolationType;
import lombok.extern.slf4j.Slf4j;
/**
* A base class for @see ControllerAdvice
* that provides centralized exception handling across all
* RequestMapping methods through ExceptionHandler methods.
*
*
* This class provides ExceptionHandler methods for handling
* multiple exceptions. This method returns a @see StateServiceResponse
* for writing to the response with a @see HttpResponse.
*
*
*
* Note that in order for a controller or method to call this base class,
* a class/interface must be called to extends this base class,
* annotated with @see ControllerAdvice indicating base package
* or controller address.
*
*
* @author Ekansh Tiwari
* @version 1.0.0
* @since 2020-06-02
* @see AccessGate Labs Response Builder on GitHub
* @see MIT License
*/
@Order(Ordered.HIGHEST_PRECEDENCE)
@ControllerAdvice
@Slf4j
@Validated
public class RestExceptionHandler extends ResponseEntityExceptionHandler {
/**
* Handle MissingServletRequestParameterException. Triggered when a 'required' request parameter is missing.
*
* @param ex Request Parameter exception @see MissingServletRequestParameterException
* @param headers HttpHeader @see HttpHeaders
* @param status HttpStatus @see HttpStatus
* @param request Request @see WebRequest
* @return StateServiceResponse Object @see StateServiceResponse
*/
@Override
protected ResponseEntity