Restore base class of MissingServletRequestPartException

Effectively reverts commit #ad2722.

Closes gh-28455
This commit is contained in:
rstoyanchev 2022-05-26 13:01:28 +01:00
parent cc56da7735
commit 2269c0063a
2 changed files with 37 additions and 6 deletions

View File

@ -29,14 +29,14 @@ import org.springframework.http.ProblemDetail;
* <p>{@link ErrorResponseException} is a default implementation of this
* interface and a convenient base class for other exceptions to use.
*
* <p>An {@code @ExceptionHandler} method can use
* {@link org.springframework.http.ResponseEntity#of(ErrorResponse)} to map an
* {@code ErrorResponse} to a {@code ResponseEntity}.
* <p>{@code ErrorResponse} is supported as a return value from
* {@code @ExceptionHandler} methods that render directly to the response, e.g.
* by being marked {@code @ResponseBody}, or declared in an
* {@code @RestController} or {@code RestControllerAdvice} class.
*
* @author Rossen Stoyanchev
* @since 6.0
* @see ErrorResponseException
* @see org.springframework.http.ResponseEntity#of(ErrorResponse)
*/
public interface ErrorResponse {

View File

@ -16,7 +16,12 @@
package org.springframework.web.multipart.support;
import org.springframework.web.bind.ServletRequestBindingException;
import jakarta.servlet.ServletException;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.ProblemDetail;
import org.springframework.web.ErrorResponse;
import org.springframework.web.multipart.MultipartResolver;
/**
@ -26,14 +31,22 @@ import org.springframework.web.multipart.MultipartResolver;
* is not configured correctly for processing multipart requests, e.g. there
* is no {@link MultipartResolver}.
*
* <p><strong>Note:</strong> This exception does not extend from
* {@link org.springframework.web.bind.ServletRequestBindingException} because
* it can also be raised at a lower level, i.e. from this package which does
* low level multipart request parsing, independent of higher level request
* binding features.
*
* @author Rossen Stoyanchev
* @since 3.1
*/
@SuppressWarnings("serial")
public class MissingServletRequestPartException extends ServletRequestBindingException {
public class MissingServletRequestPartException extends ServletException implements ErrorResponse {
private final String requestPartName;
private final ProblemDetail body = ProblemDetail.forStatus(getStatusCode());
/**
* Constructor for MissingServletRequestPartException.
@ -53,4 +66,22 @@ public class MissingServletRequestPartException extends ServletRequestBindingExc
return this.requestPartName;
}
/**
* Return the HTTP status code to use for the response.
*/
@Override
public HttpStatusCode getStatusCode() {
return HttpStatus.BAD_REQUEST;
}
/**
* Return the body for the response, formatted as an RFC 7807
* {@link ProblemDetail} whose {@link ProblemDetail#getStatus() status}
* should match the response status.
*/
@Override
public ProblemDetail getBody() {
return this.body;
}
}