Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down