@ -21,6 +21,9 @@ import java.util.HashMap;
import java.util.List ;
import java.util.List ;
import java.util.Map ;
import java.util.Map ;
import org.springframework.core.codec.CodecException ;
import org.springframework.http.HttpStatus ;
import org.springframework.web.server.ResponseStatusException ;
import reactor.core.publisher.Flux ;
import reactor.core.publisher.Flux ;
import reactor.core.publisher.Mono ;
import reactor.core.publisher.Mono ;
@ -85,7 +88,9 @@ public class DecoderHttpMessageReader<T> implements HttpMessageReader<T> {
Map < String , Object > hints ) {
Map < String , Object > hints ) {
MediaType contentType = getContentType ( message ) ;
MediaType contentType = getContentType ( message ) ;
return this . decoder . decode ( message . getBody ( ) , elementType , contentType , hints ) ;
return this . decoder
. decode ( message . getBody ( ) , elementType , contentType , hints )
. mapError ( this : : mapError ) ;
}
}
@Override
@Override
@ -93,7 +98,9 @@ public class DecoderHttpMessageReader<T> implements HttpMessageReader<T> {
Map < String , Object > hints ) {
Map < String , Object > hints ) {
MediaType contentType = getContentType ( message ) ;
MediaType contentType = getContentType ( message ) ;
return this . decoder . decodeToMono ( message . getBody ( ) , elementType , contentType , hints ) ;
return this . decoder
. decodeToMono ( message . getBody ( ) , elementType , contentType , hints )
. mapError ( this : : mapError ) ;
}
}
private MediaType getContentType ( HttpMessage inputMessage ) {
private MediaType getContentType ( HttpMessage inputMessage ) {
@ -101,6 +108,16 @@ public class DecoderHttpMessageReader<T> implements HttpMessageReader<T> {
return ( contentType ! = null ? contentType : MediaType . APPLICATION_OCTET_STREAM ) ;
return ( contentType ! = null ? contentType : MediaType . APPLICATION_OCTET_STREAM ) ;
}
}
private Throwable mapError ( Throwable ex ) {
if ( ex instanceof ResponseStatusException ) {
return ex ;
}
else if ( ex instanceof CodecException ) {
return new ResponseStatusException ( HttpStatus . BAD_REQUEST , "Failed to decode HTTP message" , ex ) ;
}
return new ResponseStatusException ( HttpStatus . INTERNAL_SERVER_ERROR , "Failed to decode HTTP message" , ex ) ;
}
// Server-side only...
// Server-side only...