39import org.springframework.web.bind.annotation.RestControllerAdvice;
40import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
41import org.springframework.web.multipart.MaxUploadSizeExceededException;
42import org.springframework.web.server.ResponseStatusException;
43import org.springframework.web.servlet.resource.NoResourceFoundException;
44import pro.nikolaev.restutils.dto.ApiError;
45import pro.nikolaev.restutils.exceptions.ApiException;
46
47import java.text.MessageFormat;
48
49/**
50 * Class representing {@link RestControllerAdvice} bean for handling MVC exception.
51 *
52 * @author Ilya Nikolaev
53 * @version 1.0
54 */
55@RestControllerAdvice
56public class ExceptionHandlingAdvice {
57 private static final String BAD_REQUEST = "Некорректный запрос";
58 private final Logger logger = LoggerFactory.getLogger(ExceptionHandlingAdvice.class);
59 private final long maxFileSize;
60 private final long maxRequestSize;
61
62 public ExceptionHandlingAdvice(MultipartConfigElement multipartConfigElement) {
63 this.maxFileSize = DataSize.ofBytes(multipartConfigElement.getMaxFileSize()).toMegabytes();
64 this.maxRequestSize = DataSize.ofBytes(multipartConfigElement.getMaxRequestSize()).toMegabytes();
65 }