Ether Framework
Unified API docs for Ether modules
Loading...
Searching...
No Matches
ProblemDetails.java
Go to the documentation of this file.
1package dev.rafex.ether.http.problem.model;
2
3/*-
4 * #%L
5 * ether-http-problem
6 * %%
7 * Copyright (C) 2025 - 2026 Raúl Eduardo González Argote
8 * %%
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 * THE SOFTWARE.
26 * #L%
27 */
28
29import java.net.URI;
30import java.util.LinkedHashMap;
31import java.util.Map;
32
33public record ProblemDetails(URI type, String title, int status, String detail, URI instance,
34 Map<String, Object> properties) {
35
36 public ProblemDetails {
37 type = type == null ? URI.create("about:blank") : type;
38 title = title == null || title.isBlank() ? "Unknown problem" : title;
39 detail = detail == null ? "" : detail;
40 properties = properties == null ? Map.of() : Map.copyOf(new LinkedHashMap<>(properties));
41 }
42
43 public static Builder builder() {
44 return new Builder();
45 }
46
47 public static ProblemDetails of(final int status, final String title, final String detail) {
48 return builder().status(status).title(title).detail(detail).build();
49 }
50
51 public static final class Builder {
52 private URI type = URI.create("about:blank");
53 private String title;
54 private int status;
55 private String detail = "";
56 private URI instance;
57 private final Map<String, Object> properties = new LinkedHashMap<>();
58
59 public Builder type(final URI type) {
60 this.type = type;
61 return this;
62 }
63
64 public Builder title(final String title) {
65 this.title = title;
66 return this;
67 }
68
69 public Builder status(final int status) {
70 this.status = status;
71 return this;
72 }
73
74 public Builder detail(final String detail) {
75 this.detail = detail;
76 return this;
77 }
78
79 public Builder instance(final URI instance) {
80 this.instance = instance;
81 return this;
82 }
83
84 public Builder property(final String key, final Object value) {
85 this.properties.put(key, value);
86 return this;
87 }
88
89 public ProblemDetails build() {
90 return new ProblemDetails(type, title, status, detail, instance, properties);
91 }
92 }
93}
record ProblemDetails(URI type, String title, int status, String detail, URI instance, Map< String, Object > properties)