Skip to content

Latest commit

 

History

History

riptide-problem

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Riptide: Problem

Lifebelt

Javadoc Maven Central

Riptide: Problem adds application/problem+json support to Riptide using zalando/problem.

Example

http.post("/").dispatch(series(),
    on(SUCCESSFUL).call(pass()),
    anySeries().call(problemHandling()));

Features

  • reusable
  • content negotiation
  • problem propagation

Dependencies

  • Riptide: Core
  • Problem

Installation

Add the following dependency to your project:

<dependency>
    <groupId>org.zalando</groupId>
    <artifactId>riptide-problem</artifactId>
    <version>${riptide.version}</version>
</dependency>

Usage

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
}

Custom Handling

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))));

Fallback Route

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
}

Getting Help

If you have questions, concerns, bug reports, etc., please file an issue in this repository's Issue Tracker.

Getting Involved/Contributing

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.