@ -16,7 +16,12 @@
@@ -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;
@@ -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
@@ -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 ;
}
}