diff options
author | Harald Musum <musum@yahooinc.com> | 2023-05-22 14:53:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-22 14:53:09 +0200 |
commit | e8028eba6ecc43cf4e5ab22a6c838becc9581792 (patch) | |
tree | 1d7c655bcadbb2f15964cf5d7c70c95bbf862e09 /controller-api | |
parent | 122c0fe9496ea4004d33694174f4251eb1e5b446 (diff) |
Revert "Use another exception and error in response when quota is exceed"
Diffstat (limited to 'controller-api')
-rw-r--r-- | controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/ConfigServerException.java | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/ConfigServerException.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/ConfigServerException.java index 7b5166dc84e..2b35334e14b 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/ConfigServerException.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/ConfigServerException.java @@ -1,6 +1,13 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.hosted.controller.api.integration.configserver; +import com.yahoo.slime.Inspector; +import com.yahoo.slime.SlimeUtils; + +import java.util.stream.Stream; + +import static java.nio.charset.StandardCharsets.UTF_8; + /** * An exception due to server error, a bad request, or similar. * @@ -42,8 +49,17 @@ public class ConfigServerException extends RuntimeException { CERTIFICATE_NOT_READY, LOAD_BALANCER_NOT_READY, INCOMPLETE_RESPONSE, - CONFIG_NOT_CONVERGED, - QUOTA_EXCEEDED + CONFIG_NOT_CONVERGED + } + + public static ConfigServerException readException(byte[] body, String context) { + Inspector root = SlimeUtils.jsonToSlime(body).get(); + String codeName = root.field("error-code").asString(); + ErrorCode code = Stream.of(ErrorCode.values()) + .filter(value -> value.name().equals(codeName)) + .findAny().orElse(ErrorCode.INCOMPLETE_RESPONSE); + String message = root.field("message").valid() ? root.field("message").asString() : new String(body, UTF_8); + return new ConfigServerException(code, message, context); } } |