Class WebfluxProblem
java.lang.Object
dmx.fun.spring.webflux.WebfluxProblem
Renders dmx-fun failures as RFC 7807
ProblemDetail responses (application/problem+json), so error handling in a
fun-spring-webflux application produces a standard problem document instead of an
ad-hoc body.
The problemDetail(HttpStatus, Function) factories return an ErrorHttpMapper /
ThrowableHttpMapper you pass to WebfluxFun.fromResult(Mono, ErrorHttpMapper) / WebfluxFun.fromTry(Mono, ThrowableHttpMapper);
fromValidated(Mono) renders accumulated validation failures as a 400 problem whose
errors property lists every violation.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <V,E> reactor.core.publisher.Mono <org.springframework.web.reactive.function.server.ServerResponse> fromValidated(reactor.core.publisher.Mono<Validated<NonEmptyList<E>, V>> source) Maps aMono<Validated<NonEmptyList<E>, V>>to a response:Valid→200with the value,Invalid→400ProblemDetailwhoseerrorsproperty lists every accumulated error, empty →404.static ThrowableHttpMapperproblemDetail(org.springframework.http.HttpStatus status) Returns aThrowableHttpMapperthat renders aTry.Failureas aProblemDetailwith the givenstatusand the exception message as the detail.static <E> ErrorHttpMapper<E> problemDetail(org.springframework.http.HttpStatus status, Function<? super E, String> detail) Returns anErrorHttpMapperthat renders aResult.Erras aProblemDetailwith the givenstatusand adetailderived from the error value.
-
Method Details
-
problemDetail
public static <E> ErrorHttpMapper<E> problemDetail(org.springframework.http.HttpStatus status, Function<? super E, String> detail) Returns anErrorHttpMapperthat renders aResult.Erras aProblemDetailwith the givenstatusand adetailderived from the error value. Use it withWebfluxFun.fromResult(Mono, ErrorHttpMapper).- Type Parameters:
E- the domain error type- Parameters:
status- the HTTP status for the problemdetail- derives the problem's human-readable detail from the error value- Returns:
- an
ErrorHttpMapperproducing a problem-detail response
-
problemDetail
Returns aThrowableHttpMapperthat renders aTry.Failureas aProblemDetailwith the givenstatusand the exception message as the detail. Use it withWebfluxFun.fromTry(Mono, ThrowableHttpMapper).- Parameters:
status- the HTTP status for the problem- Returns:
- a
ThrowableHttpMapperproducing a problem-detail response
-
fromValidated
public static <V,E> reactor.core.publisher.Mono<org.springframework.web.reactive.function.server.ServerResponse> fromValidated(reactor.core.publisher.Mono<Validated<NonEmptyList<E>, V>> source) Maps aMono<Validated<NonEmptyList<E>, V>>to a response:Valid→200with the value,Invalid→400ProblemDetailwhoseerrorsproperty lists every accumulated error, empty →404.- Type Parameters:
V- the value typeE- the element type of the accumulated errors- Parameters:
source- the upstream validated value- Returns:
- the HTTP response
-