diff options
author | Bjørn Christian Seime <bjorncs@verizonmedia.com> | 2021-04-12 17:07:13 +0200 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@verizonmedia.com> | 2021-04-12 20:57:24 +0200 |
commit | 8d6a61325452ffb1d40a518f075752b9c5d81e5c (patch) | |
tree | 5def07dc4a9abf59d96ad1a201a3afe1f66a4b90 /container-core/src/main/java/com/yahoo | |
parent | 52de2547b77cda5fca3dd8369d27a440841f4fb8 (diff) |
Add type for '409 - Conflict' + extra constructors
Diffstat (limited to 'container-core/src/main/java/com/yahoo')
-rw-r--r-- | container-core/src/main/java/com/yahoo/restapi/ErrorResponse.java | 8 | ||||
-rw-r--r-- | container-core/src/main/java/com/yahoo/restapi/RestApiException.java | 17 |
2 files changed, 21 insertions, 4 deletions
diff --git a/container-core/src/main/java/com/yahoo/restapi/ErrorResponse.java b/container-core/src/main/java/com/yahoo/restapi/ErrorResponse.java index d3e81a10720..1885a0c970c 100644 --- a/container-core/src/main/java/com/yahoo/restapi/ErrorResponse.java +++ b/container-core/src/main/java/com/yahoo/restapi/ErrorResponse.java @@ -5,6 +5,7 @@ import com.yahoo.slime.Cursor; import com.yahoo.slime.Slime; import static com.yahoo.jdisc.Response.Status.BAD_REQUEST; +import static com.yahoo.jdisc.Response.Status.CONFLICT; import static com.yahoo.jdisc.Response.Status.FORBIDDEN; import static com.yahoo.jdisc.Response.Status.INTERNAL_SERVER_ERROR; import static com.yahoo.jdisc.Response.Status.METHOD_NOT_ALLOWED; @@ -24,7 +25,8 @@ public class ErrorResponse extends SlimeJsonResponse { FORBIDDEN, METHOD_NOT_ALLOWED, INTERNAL_SERVER_ERROR, - UNAUTHORIZED + UNAUTHORIZED, + CONFLICT } public ErrorResponse(int statusCode, String errorType, String message) { @@ -63,4 +65,8 @@ public class ErrorResponse extends SlimeJsonResponse { return new ErrorResponse(METHOD_NOT_ALLOWED, errorCodes.METHOD_NOT_ALLOWED.name(), message); } + public static ErrorResponse conflict(String message) { + return new ErrorResponse(CONFLICT, errorCodes.CONFLICT.name(), message); + } + } diff --git a/container-core/src/main/java/com/yahoo/restapi/RestApiException.java b/container-core/src/main/java/com/yahoo/restapi/RestApiException.java index ac3aa647b87..da853f91402 100644 --- a/container-core/src/main/java/com/yahoo/restapi/RestApiException.java +++ b/container-core/src/main/java/com/yahoo/restapi/RestApiException.java @@ -41,7 +41,10 @@ public class RestApiException extends RuntimeException { public HttpResponse response() { return response; } public static class NotFoundException extends RestApiException { - public NotFoundException() { super(ErrorResponse::notFoundError, "Not Found", null); } + public NotFoundException() { this(null, null); } + public NotFoundException(Throwable cause) { this(cause.getMessage(), cause); } + public NotFoundException(String message) { this(message, null); } + public NotFoundException(String message, Throwable cause) { super(ErrorResponse::notFoundError, message, cause); } } public static class MethodNotAllowed extends RestApiException { @@ -52,12 +55,14 @@ public class RestApiException extends RuntimeException { } public static class BadRequest extends RestApiException { - public BadRequest(String message) { super(ErrorResponse::badRequest, message, null); } + public BadRequest(String message) { this(message, null); } + public BadRequest(Throwable cause) { this(cause.getMessage(), cause); } public BadRequest(String message, Throwable cause) { super(ErrorResponse::badRequest, message, cause); } } public static class InternalServerError extends RestApiException { - public InternalServerError(String message) { super(ErrorResponse::internalServerError, message, null); } + public InternalServerError(String message) { this(message, null); } + public InternalServerError(Throwable cause) { this(cause.getMessage(), cause); } public InternalServerError(String message, Throwable cause) { super(ErrorResponse::internalServerError, message, cause); } } @@ -65,4 +70,10 @@ public class RestApiException extends RuntimeException { public Forbidden(String message) { super(ErrorResponse::forbidden, message, null); } public Forbidden(String message, Throwable cause) { super(ErrorResponse::forbidden, message, cause); } } + + public static class Conflict extends RestApiException { + public Conflict() { this("Conflict", null); } + public Conflict(String message) { this(message, null); } + public Conflict(String message, Throwable cause) { super(ErrorResponse::conflict, message, cause); } + } } |