From 75e74dd77df321d36aba84d7a0a231608dfc4732 Mon Sep 17 00:00:00 2001 From: kalnik-a-a Date: Wed, 6 Apr 2016 14:48:06 +0300 Subject: [PATCH] SparkPostErrorServerResponseException added --- .../SparkPostErrorServerResponseException.java | 18 ++++++++++++++++++ .../sparkpost/transport/RestConnection.java | 6 +++++- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 libs/sparkpost-lib/src/main/java/com/sparkpost/exception/SparkPostErrorServerResponseException.java diff --git a/libs/sparkpost-lib/src/main/java/com/sparkpost/exception/SparkPostErrorServerResponseException.java b/libs/sparkpost-lib/src/main/java/com/sparkpost/exception/SparkPostErrorServerResponseException.java new file mode 100644 index 0000000..e65c9bb --- /dev/null +++ b/libs/sparkpost-lib/src/main/java/com/sparkpost/exception/SparkPostErrorServerResponseException.java @@ -0,0 +1,18 @@ +package com.sparkpost.exception; + +import com.yepher.jsondoc.annotations.Description; +import lombok.Getter; + +public class SparkPostErrorServerResponseException extends SparkPostException { + + private static final long serialVersionUID = -7196264905004169555L; + + @Getter + @Description(value = "HTTP Response Code generated by request", sample = {"426"}) + private int responseCode = -1; + + public SparkPostErrorServerResponseException(String message, int responseCode) { + super(message); + this.responseCode = responseCode; + } +} diff --git a/libs/sparkpost-lib/src/main/java/com/sparkpost/transport/RestConnection.java b/libs/sparkpost-lib/src/main/java/com/sparkpost/transport/RestConnection.java index a3a97c5..4c6e4a8 100644 --- a/libs/sparkpost-lib/src/main/java/com/sparkpost/transport/RestConnection.java +++ b/libs/sparkpost-lib/src/main/java/com/sparkpost/transport/RestConnection.java @@ -12,6 +12,7 @@ import java.net.ProtocolException; import java.net.URL; +import com.sparkpost.exception.SparkPostErrorServerResponseException; import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; @@ -273,7 +274,10 @@ private Response receiveResponse(HttpURLConnection conn, Response response) thro } else if (response.getResponseCode() == ACCESS_FORBIDDEN_RESPONSE_STATUS_CODE) { throw new SparkPostAccessForbiddenException(); } else { - throw new SparkPostException("Error reading server response: " + ex.toString() + ": " + sb.toString() + "(" + response.getResponseMessage() + ")"); + throw new SparkPostErrorServerResponseException( + "Error reading server response: " + ex.toString() + ": " + sb.toString() + "(" + response.getResponseMessage() + ")", + response.getResponseCode() + ); } } return response;