summaryrefslogtreecommitdiffstats
path: root/controller-api
diff options
context:
space:
mode:
authorHarald Musum <musum@yahooinc.com>2023-05-22 15:02:04 +0200
committerHarald Musum <musum@yahooinc.com>2023-05-22 15:02:04 +0200
commit7e46a20093e1b9be9510a666cb926277b9a92480 (patch)
tree54ae6bee189d855d09f50d77d0a271f0351b6a99 /controller-api
parentf8fda07e9542664277e1835c9d6d1fd136ea6b6a (diff)
Add back method used by code in internal repo
Diffstat (limited to 'controller-api')
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/ConfigServerException.java18
1 files changed, 18 insertions, 0 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..94a565b2974 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.
*
@@ -46,4 +53,15 @@ public class ConfigServerException extends RuntimeException {
QUOTA_EXCEEDED
}
+ // Note: Used by code in internal repo
+ 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);
+ }
+
}