Comments (4)
One thing you could simply do in code like this is put your else if (500 <= spex.getResponseCode() && spex.getResponseCode() < 510){..
with this code so it retries once:
IRestConnection connection = new RestConnection(this.client, getEndPoint());
ResourceTransmissions.create(connection, 0, transmission);
If you want a more persistent retry you will want to be careful and have some sort of retry cap and probably an exponential backoff of some sort in case this is a recurring error. Is there a particular problem you are seeing where you are getting a log to 510
errors?
from java-sparkpost.
This is the block where that snippet is from and what we are doing. Basically if its a suppressed error, we mark it a certain way in our db. What i'm trying to do is check the response code and if it's a 50x, to not mark the db... and on the next loop of our app, it'll attempt to connect/send again (it's not very aggressive so i'm not worried about that part). But I'm never seeing it hit my responsecode check. I'm assuming the block with the< 510
means only 500-509.
catch (SparkPostErrorServerResponseException spex) {
boolean handled = false;
// further classify error message if possible
try {
Pattern p = Pattern.compile("[^\\{]*(\\{.*\\})[^\\}]*");
Matcher m = p.matcher(spex.getMessage());
if (m.find(0)) {
String json = m.group(1);
JsonParser jsonParser = new JsonParser();
JsonObject jo = (JsonObject) jsonParser.parse(json);
// check if the JSON response is "Suppression"
if (jo.getAsJsonArray("errors").get(0).getAsJsonObject().get("code").getAsString().equals("1902")) {
EmailDAO.markAsUnsubscribed(conn, em);
Logger.log("Email not sent because user unsubscribed " + em.id);
handled = true;
} else if (500 <= spex.getResponseCode() && spex.getResponseCode() < 510){
Logger.log("Sparkpost " + spex.getResponseCode() + " errors, skipping for now: " + em.id);
handled = true;
}
}
} catch (Exception ex) {
Logger.error("Unable to determine SparkPost error: " + em.id, ex);
}
if (!handled) {
Logger.error("SparkPost unknown error processing email: " + em.id, spex);
// mark email as error first
try {
EmailDAO.markAsError(conn, em);
} catch (SQLException ex) {
Logger.error("Error marking email as error: " + em.id, ex);
}
}
from java-sparkpost.
I was thinking something like this. I am not quite sure how to test this since I don't know how to force a HTTP 5XX error.
private void forceFiveHundredError(int retries) throws SparkPostException, IOException {
this.client = this.newConfiguredClient();
IRestConnection connection = new RestConnection(this.client, "https://api.sparkpost.com/api/v1");
try {
// Do something to foce and internal server error
ResourceSendingDomains.list(connection);
throw new IllegalStateException("Error: Expected an exception");
} catch (SparkPostException e) {
if (e.getServerErrorResponses() != null) {
System.out.println("Got response from server.");
if (e.getServerErrorResponses().getResponseCode() >= 500 && e.getServerErrorResponses().getResponseCode() <= 599) {
System.out.println("Got a 5xx level error");
try {
// wait before retrying
Thread.sleep(retries * 10000);
} catch (InterruptedException e1) {
}
forceFiveHundredError(retries + 1);
}
} else {
System.out.println("This is some other unexpected error!!!");
}
}
}
from java-sparkpost.
Closing this. If the previous comment does not answer the question please re-open the ticket and let me know what I missed.
from java-sparkpost.
Related Issues (20)
- Log4j critical vulnerability!! HOT 4
- SuppressionList update endpoints throw com.google.gson.JsonSyntaxException
- RestConnection does not honor Client base URL
- Upgrade to Log4J 2.17.1
- Webhook events no longer derive from AbstractWebhookEvent, making getting type more difficult
- Webhook fields initial_pixel and open_tracking are presented as int, rather than boolean in event classes, making deserialization harder
- GSON error when calling insertOrUpdate or insertOrUpdateBulk
- Add 'template_id' key in X-MSYS-API Custom Header
- SparkPost/Java
- Add ability to GZIP post data HOT 1
- Switch to using SLF4J HOT 2
- Webhook active property missing from model HOT 2
- Webhook properties are out of date HOT 1
- attach pdf HOT 2
- Webhook resource is missing /validate endpoint
- SparkPost Java API Suppression list limitations HOT 1
- event webhook - handle ping events
- Message Event API ending point changed - please update HOT 1
- TransimisionBase should allow other types than String for Metadata value HOT 2
- Subaccount CRUDs
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from java-sparkpost.