Skip to content

Commit da6251c

Browse files
Add note about factory methods
1 parent 0aa3171 commit da6251c

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

docs/02-problem4j-core.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@ try {
7272
}
7373
```
7474

75+
For convenience, `Problem` objects can also be created using static `Problem.of` factory methods.
76+
77+
```java
78+
static Problem Problem.of(int status);
79+
static Problem Problem.of(int status, @Nullable String detail);
80+
static Problem Problem.of(String title, int status);
81+
static Problem Problem.of(String title, int status, @Nullable String detail);
82+
static Problem Problem.of(URI type, String title, int status);
83+
static Problem Problem.of(URI type, String title, int status, @Nullable String detail);
84+
```
85+
7586
## Throw exception annotated with `@ProblemMapping`
7687

7788
If an exception is annotated with `@ProblemMapping`, extracting the underlying `Problem` from it requires a bit of

docs/04-problem4j-spring/02-exception-handling.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,17 @@ Will result in following response body:
222222
}
223223
```
224224

225+
For convenience, `Problem` objects can also be created using static `Problem.of` factory methods.
226+
227+
```java
228+
static Problem Problem.of(int status);
229+
static Problem Problem.of(int status, @Nullable String detail);
230+
static Problem Problem.of(String title, int status);
231+
static Problem Problem.of(String title, int status, @Nullable String detail);
232+
static Problem Problem.of(URI type, String title, int status);
233+
static Problem Problem.of(URI type, String title, int status, @Nullable String detail);
234+
```
235+
225236
## Spring's build-in `@ResponseStatus` annotation
226237

227238
If your exception is annotated with Spring's built-in `@ResponseStatus`, the library will use the specified HTTP status

0 commit comments

Comments
 (0)