Skip to content

Commit 5ab42be

Browse files
committed
refactor: Extract Bad Request title constant and use HTTP_BAD_REQUEST
1 parent f63d5e9 commit 5ab42be

1 file changed

Lines changed: 26 additions & 12 deletions

File tree

src/main/java/com/retailsvc/http/internal/ProblemDetail.java

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.retailsvc.http.internal;
22

3+
import static java.net.HttpURLConnection.HTTP_BAD_REQUEST;
4+
35
import com.retailsvc.http.BadRequestException;
46
import com.retailsvc.http.validate.ValidationError;
57
import java.util.ArrayList;
@@ -28,9 +30,11 @@ public record ProblemDetail(
2830
public record Entry(String pointer, String keyword, String detail) {}
2931

3032
private static final String DEFAULT_TYPE = "about:blank";
33+
private static final String BAD_REQUEST = "Bad Request";
3134

3235
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));
3438
}
3539

3640
public static ProblemDetail forBadRequest(BadRequestException e) {
@@ -76,18 +80,28 @@ private static int depth(String pointer) {
7680

7781
private static final Map<Integer, String> TITLES =
7882
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");
89103

90104
private static String titleFor(int status) {
91-
return TITLES.getOrDefault(status, "Bad Request");
105+
return TITLES.getOrDefault(status, BAD_REQUEST);
92106
}
93107
}

0 commit comments

Comments
 (0)