You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/asciidoc/problem-details.adoc
+16-16Lines changed: 16 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,25 +46,25 @@ problem.details {
46
46
47
47
==== Creating problems
48
48
49
-
`HttpProblem` class represents the `RFC 7807` model. It is the main entity you need to work with to produce the problem.
49
+
javadoc:problem.HttpProblem[] class represents the `RFC 7807` model. It is the main entity you need to work with to produce the problem.
50
50
51
51
===== Static helpers
52
52
53
-
There are several handy static methods to produce a simple `HttpProblem`:
53
+
There are several handy static methods to produce a simple javadoc:problem.HttpProblem[]:
54
54
55
-
- `HttpProblem.valueOf(StatusCode status)` - will pick the title by status code.
55
+
- javadoc:problem.HttpProblem[valueOf, io.jooby.StatusCode] - will pick the title by status code.
56
56
Don't overuse it, the problem should have meaningful `title` and `detail` when possible.
57
-
- `HttpProblem.valueOf(StatusCode status, String title)` - with custom `title`
58
-
- `HttpProblem.valueOf(StatusCode status, String title, String detail)` - with `title` and `detail`
57
+
- javadoc:problem.HttpProblem[valueOf, io.jooby.StatusCode, java.lang.String] - with custom `title`
58
+
- javadoc:problem.HttpProblem[valueOf, io.jooby.StatusCode, java.lang.String, java.lang.String] - with `title` and `detail`
59
59
60
-
and couple shorthands for the most common validation codes:
60
+
and a couple of shorthands for the most common validation codes:
61
61
62
-
- `HttpProblem.badRequest(String title, String detail)` - for _400 Bad Request_
63
-
- `HttpProblem.notFound(String title, String detail)` - for _404 Not Found_
64
-
- `HttpProblem.unprocessableEntity(String title, String detail)` - for _422 Unprocessable Entity_
65
-
- `HttpProblem.internalServerError()` - for _500 Internal Server Error_
62
+
- javadoc:problem.HttpProblem[badRequest, java.lang.String, java.lang.String] - for _400 Bad Request_
63
+
- javadoc:problem.HttpProblem[notFound, java.lang.String, java.lang.String] - for _404 Not Found_
64
+
- javadoc:problem.HttpProblem[unprocessableEntity, java.lang.String, java.lang.String] - for _422 Unprocessable Entity_
65
+
- javadoc:problem.HttpProblem[internalServerError] - for _500 Internal Server Error_
66
66
67
-
`HttpProblem` extends `RuntimeException` so you can naturally throw it (as you do with exceptions):
67
+
javadoc:problem.HttpProblem[] extends `RuntimeException` so you can naturally throw it (as you do with exceptions):
68
68
69
69
.Java
70
70
[source,java,role="primary"]
@@ -137,7 +137,7 @@ throw HttpProblem.builder()
137
137
138
138
`RFC 7807` has a simple extension model: APIs are free to add any other properties to the problem details object, so all properties other than the five ones listed above are extensions.
139
139
140
-
However, variadic root level fields are usually not very convenient for (de)serialization (especially in statically typed languages). That's why `HttpProblem` implementation grabs all extensions under a single root field `parameters`. You can add parameters using builder like this:
140
+
However, variadic root level fields are usually not very convenient for (de)serialization (especially in statically typed languages). That's why javadoc:problem.HttpProblem[] implementation grabs all extensions under a single root field `parameters`. You can add parameters using builder like this:
141
141
142
142
[source,java]
143
143
----
@@ -172,7 +172,7 @@ Resulting response:
172
172
173
173
==== Adding headers
174
174
175
-
Some `HTTP` codes (like `413` or `426`) require additional response headers, or it may be required by third-party system/integration. `HttpProblem` support additional headers in response:
175
+
Some `HTTP` codes (like `413` or `426`) require additional response headers, or it may be required by third-party system/integration. javadoc:problem.HttpProblem[] support additional headers in response:
176
176
177
177
[source,java]
178
178
----
@@ -218,12 +218,12 @@ In response:
218
218
219
219
[TIP]
220
220
====
221
-
If you need to enrich errors with more information feel free to extend `HttpProblem.Error` and make your custom errors model.
221
+
If you need to enrich errors with more information feel free to extend javadoc:problem.HttpProblem.Error[] and make your custom errors model.
222
222
====
223
223
224
224
==== Custom `Exception` to `HttpProblem`
225
225
226
-
Apparently, you may already have many custom `Exception` classes in the codebase, and you want to make them `Problem Details` compliant without complete re-write. You can achieve this by implementing `HttpProblemMappable` interface. It allows you to control how exceptions should be transformed into `HttpProblem` if default behaviour doesn't suite your needs:
226
+
Apparently, you may already have many custom `Exception` classes in the codebase, and you want to make them `Problem Details` compliant without complete re-write. You can achieve this by implementing javadoc:problem.HttpProblemMappable[] interface. It allows you to control how exceptions should be transformed into javadoc:problem.HttpProblem if default behaviour doesn't suite your needs:
227
227
228
228
[source,java]
229
229
----
@@ -242,7 +242,7 @@ public class MyException implements HttpProblemMappable {
242
242
243
243
==== Custom Problems
244
244
245
-
Extending `HttpProblem` and utilizing builder functionality makes it really easy:
245
+
Extending javadoc:problem.HttpProblem[] and utilizing builder functionality makes it really easy:
0 commit comments