1package dev.rafex.ether.http.problem.mapper;
29import java.util.Objects;
31import dev.rafex.ether.http.core.DefaultErrorMapper;
32import dev.rafex.ether.http.core.ErrorMapper;
33import dev.rafex.ether.http.core.HttpError;
34import dev.rafex.ether.http.problem.exception.ProblemException;
35import dev.rafex.ether.http.problem.model.ProblemDetails;
46 this.fallback = Objects.requireNonNull(fallback,
"fallback");
50 public HttpError
map(
final Throwable error) {
51 return switch (error) {
53 final var
problem = pe.problem();
56 default -> fallback.map(error);
60 private static String problemCode(
final ProblemDetails
problem) {
61 return switch (
problem.properties().get(
"code")) {
62 case String value when !value.isBlank() -> value;
67 private static String safe(
final String detail,
final String fallback) {
68 if (detail !=
null && !detail.isBlank()) {
71 return fallback ==
null || fallback.isBlank() ?
"problem" : fallback;
HttpError map(final Throwable error)
ProblemHttpErrorMapper(final ErrorMapper fallback)
Problem Details support for consistent HTTP error payloads.