Riptide: Problem adds application/problem+json
support to Riptide using
zalando/problem.
http.post("/").dispatch(series(),
on(SUCCESSFUL).call(pass()),
anySeries().call(problemHandling()));
- reusable
- content negotiation
- problem propagation
- Java 8
- Riptide: Core
- Problem
Add the following dependency to your project:
<dependency>
<groupId>org.zalando</groupId>
<artifactId>riptide-problem</artifactId>
<version>${riptide.version}</version>
</dependency>
If a problem is being received it will be mapped to a
ThrowableProblem
/Exceptional
. It can be inspected as the
cause of the CompletionException
:
import static org.zalando.riptide.problem.ProblemRoute.problemHandling;
try {
http.post("/").dispatch(series(),
on(SUCCESSFUL).call(pass()),
anySeries().call(problemHandling()))
.join();
} catch (CompletionException e) {
assert e.getCause() instanceof Problem; // TODO handle
}
If throwing a problem is not the desired behaviour one can override it by passing in a custom consumer:
http.post("/").dispatch(series(),
on(SUCCESSFUL).call(pass()),
anySeries().call(problemHandling(e -> LOG.error("Unexpected problem", e))));
If the ProblemRoute
fails to dispatch, e.g. because of a different media type, it will follow the default behaviour
of Riptide and fail with a NoRouteException
(unless a wildcard matches). This behaviour can be overridden by:
http.post("/").dispatch(series(),
on(SUCCESSFUL).call(pass()),
anySeries().call(problemHandling(call(this::onUnsupportedError))));
void onUnsupportedError(ClientHttpResponse response) throws IOException {
// TODO handle non-problem error response here
}
If you have questions, concerns, bug reports, etc., please file an issue in this repository's Issue Tracker.
To contribute, simply make a pull request and add a brief description (1-2 sentences) of your addition or change. For more details, check the contribution guidelines.