|
1 | 1 | package com.retailsvc.http.internal; |
2 | 2 |
|
| 3 | +import static java.net.HttpURLConnection.HTTP_BAD_REQUEST; |
| 4 | + |
3 | 5 | import com.retailsvc.http.BadRequestException; |
4 | 6 | import com.retailsvc.http.validate.ValidationError; |
5 | 7 | import java.util.ArrayList; |
@@ -28,9 +30,11 @@ public record ProblemDetail( |
28 | 30 | public record Entry(String pointer, String keyword, String detail) {} |
29 | 31 |
|
30 | 32 | private static final String DEFAULT_TYPE = "about:blank"; |
| 33 | + private static final String BAD_REQUEST = "Bad Request"; |
31 | 34 |
|
32 | 35 | public static ProblemDetail forValidation(ValidationError e) { |
33 | | - return new ProblemDetail(DEFAULT_TYPE, "Bad Request", 400, e.message(), entriesOf(e)); |
| 36 | + return new ProblemDetail( |
| 37 | + DEFAULT_TYPE, BAD_REQUEST, HTTP_BAD_REQUEST, e.message(), entriesOf(e)); |
34 | 38 | } |
35 | 39 |
|
36 | 40 | public static ProblemDetail forBadRequest(BadRequestException e) { |
@@ -76,18 +80,28 @@ private static int depth(String pointer) { |
76 | 80 |
|
77 | 81 | private static final Map<Integer, String> TITLES = |
78 | 82 | Map.of( |
79 | | - 400, "Bad Request", |
80 | | - 401, "Unauthorized", |
81 | | - 403, "Forbidden", |
82 | | - 404, "Not Found", |
83 | | - 405, "Method Not Allowed", |
84 | | - 409, "Conflict", |
85 | | - 410, "Gone", |
86 | | - 412, "Precondition Failed", |
87 | | - 415, "Unsupported Media Type", |
88 | | - 422, "Unprocessable Content"); |
| 83 | + HTTP_BAD_REQUEST, |
| 84 | + BAD_REQUEST, |
| 85 | + 401, |
| 86 | + "Unauthorized", |
| 87 | + 403, |
| 88 | + "Forbidden", |
| 89 | + 404, |
| 90 | + "Not Found", |
| 91 | + 405, |
| 92 | + "Method Not Allowed", |
| 93 | + 409, |
| 94 | + "Conflict", |
| 95 | + 410, |
| 96 | + "Gone", |
| 97 | + 412, |
| 98 | + "Precondition Failed", |
| 99 | + 415, |
| 100 | + "Unsupported Media Type", |
| 101 | + 422, |
| 102 | + "Unprocessable Content"); |
89 | 103 |
|
90 | 104 | private static String titleFor(int status) { |
91 | | - return TITLES.getOrDefault(status, "Bad Request"); |
| 105 | + return TITLES.getOrDefault(status, BAD_REQUEST); |
92 | 106 | } |
93 | 107 | } |
0 commit comments