summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@oath.com>2017-10-27 16:13:08 +0200
committerBjørn Christian Seime <bjorncs@oath.com>2017-10-27 16:13:08 +0200
commit6b4a177ac3a6109431e81e9302b8b7af5efe62e0 (patch)
treebfc3dc01a7268216c8e0fd3e0b32d28fc9f1582f
parent0926ed6d8a73f5207f759b1b23c3d528a76cf886 (diff)
Handle NotAuthorizedException in ApplicationApiHandler
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/ErrorResponse.java8
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java4
2 files changed, 11 insertions, 1 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/ErrorResponse.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/ErrorResponse.java
index a9643e21c00..4af833baa98 100644
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/ErrorResponse.java
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/ErrorResponse.java
@@ -11,6 +11,7 @@ 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;
import static com.yahoo.jdisc.Response.Status.NOT_FOUND;
+import static com.yahoo.jdisc.Response.Status.UNAUTHORIZED;
/**
* A HTTP JSON response containing an error code and a message
@@ -24,7 +25,8 @@ public class ErrorResponse extends SlimeJsonResponse {
BAD_REQUEST,
FORBIDDEN,
METHOD_NOT_ALLOWED,
- INTERNAL_SERVER_ERROR
+ INTERNAL_SERVER_ERROR,
+ UNAUTHORIZED
}
public ErrorResponse(int statusCode, String errorType, String message) {
@@ -55,6 +57,10 @@ public class ErrorResponse extends SlimeJsonResponse {
return new ErrorResponse(FORBIDDEN, errorCodes.FORBIDDEN.name(), message);
}
+ public static ErrorResponse unauthorized(String message) {
+ return new ErrorResponse(UNAUTHORIZED, errorCodes.UNAUTHORIZED.name(), message);
+ }
+
public static ErrorResponse methodNotAllowed(String message) {
return new ErrorResponse(METHOD_NOT_ALLOWED, errorCodes.METHOD_NOT_ALLOWED.name(), message);
}
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java
index fb3ebf18f01..77240707ee4 100644
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java
@@ -81,6 +81,7 @@ import com.yahoo.yolean.Exceptions;
import javax.ws.rs.BadRequestException;
import javax.ws.rs.ForbiddenException;
+import javax.ws.rs.NotAuthorizedException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
@@ -139,6 +140,9 @@ public class ApplicationApiHandler extends LoggingRequestHandler {
catch (ForbiddenException e) {
return ErrorResponse.forbidden(Exceptions.toMessageString(e));
}
+ catch (NotAuthorizedException e) {
+ return ErrorResponse.unauthorized(Exceptions.toMessageString(e));
+ }
catch (NotExistsException e) {
return ErrorResponse.notFoundError(Exceptions.toMessageString(e));
}