src/main/java/org/embulk/input/zendesk/clients/ZendeskRestClient.java in embulk-input-zendesk-0.3.5 vs src/main/java/org/embulk/input/zendesk/clients/ZendeskRestClient.java in embulk-input-zendesk-0.3.6

- old
+ new

@@ -1,8 +1,9 @@ package org.embulk.input.zendesk.clients; import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; import com.google.common.util.concurrent.RateLimiter; @@ -168,10 +169,21 @@ } private boolean isResponseStatusToRetry(final int status, final String message, final int retryAfter, final boolean isPreview) { if (status == HttpStatus.SC_NOT_FOUND) { + ObjectMapper objectMapper = new ObjectMapper(); + try { + JsonNode jsonNode = objectMapper.readTree(message); + if (jsonNode.has("error") && jsonNode.get("error").has("title") && jsonNode.get("error").get("title").asText().startsWith("No help desk at ")) { + throw new ConfigException("This address is not registered in Zendesk. Please check the login_url again"); + } + } + catch (IOException e) { + // In case we can't parse the message, error should not be show here + } + // 404 would be returned e.g. ticket comments are empty (on fetchRelatedObjects method) return false; } if (status == HttpStatus.SC_CONFLICT) { @@ -201,9 +213,17 @@ throw new DataException("Rate Limited. Waiting '" + retryAfter + "' seconds to re-run"); } // Won't retry for 4xx range errors except above. Almost they should be ConfigError e.g. 403 Forbidden if (status / 100 == 4) { + if (status == HttpStatus.SC_UNAUTHORIZED) { + throw new ConfigException("Cannot authenticate due to invalid login credentials"); + } + + if (status == HttpStatus.SC_FORBIDDEN) { + throw new ConfigException("You do not have access to this resource. Please contact the account owner of this help desk for further help."); + } + throw new ConfigException("Status '" + status + "', message '" + message + "'"); } logger.warn("Server returns unknown status code '" + status + "' message '" + message + "'"); return true;