private <T> Response fromTry(Try<T> t) { return t.transform(x -> Match(x).option( Case(Failure($(instanceOf(RestExceptionBadRequest.class))), () -> Response.status(400).build()), Case(Failure($(instanceOf(RestExceptionForbidden.class))), () -> Response.status(403).build()), Case(Success($()), y -> Response.ok(y).build()))) .getOrElseThrow(() -> new RuntimeException("Error processing request.", t.getCause())); }