Skip to content

Commit 7cd82b5

Browse files
Merge pull request #8 from socketlabs/nodejs-retrylogic
Nodejs retrylogic
2 parents dfd5f34 + 940b78d commit 7cd82b5

File tree

10 files changed

+697
-810
lines changed

10 files changed

+697
-810
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ This example demonstrates how to add custom headers to your email message.
174174
### [Basic send with a web proxy](https://github.com/socketlabs/socketlabs-nodejs/blob/master/examples/basic/basicSendWithProxy.js)
175175
This example demonstrates how to use a proxy with your HTTP client.
176176

177+
### [Basic send with retry enabled](https://github.com/socketlabs/socketlabs-nodejs/blob/master/examples/basic/basicSendWithRetry.js)
178+
This example demonstrates how to use the retry logic with your HTTP client.
179+
177180
### [Basic send complex example](https://github.com/socketlabs/socketlabs-nodejs/blob/master/examples/basic/basicSendComplexExample.js)
178181
This example demonstrates many features of the Basic Send, including adding multiple recipients, adding message and mailing id's, and adding an embedded image.
179182

@@ -211,6 +214,7 @@ For more information about AMP please see [AMP Project](https://amp.dev/document
211214

212215
<a name="version"></a>
213216
# Version
217+
* 1.2.1 - Adding optional retry logic for Http requests. If configured, the request will retry when certain 500 errors occur (500, 502, 503, 504)
214218
* 1.1.1 - Adding request timeout value on the client for Http requests
215219
* 1.1.0 - Adds Amp Html Support
216220
* 1.0.0 - Initial Release

examples/basic/basicSendWithRetry.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const { SocketLabsClient, EmailAddress, BasicMessage } = require('../../src/socketlabsClient');
2+
const exampleConfig = require('../exampleConfig');
3+
4+
/**
5+
* Build the message
6+
*/
7+
var message = new BasicMessage();
8+
9+
message.subject = "Sending An Email Through A Proxy";
10+
message.htmlBody = "<html><body><h1>Sending An Email Through A Proxy</h1><p>This is the Html Body of my message.</p></body></html>";
11+
message.textBody = "This is the Plain Text Body of my message.";
12+
13+
message.from = new EmailAddress("[email protected]");
14+
15+
message.to.push("[email protected]");
16+
17+
/**
18+
* Create the client
19+
*/
20+
var client = new SocketLabsClient(exampleConfig.ServerId, exampleConfig.ApiKey,
21+
{
22+
optionalProxy: "http://localhost:4433"
23+
});
24+
25+
client.numberOfRetries = 3;
26+
27+
/**
28+
* Send the message
29+
*/
30+
client.requestTimeout = 20;
31+
client.send(message).then(
32+
(res) => {
33+
console.log("Promise resolved: ")
34+
console.log(res)
35+
},
36+
(err) => {
37+
console.log("Promise rejected: ")
38+
console.log(err)
39+
}
40+
);

examples/exampleConfig.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
'use strict';
22

3+
const { endpointUrl } = require("../src/core/retryHandler");
4+
35
module.exports = {
46
ServerId: parseInt(process.env.SOCKETLABS_SERVER_ID),
57
ApiKey: process.env.SOCKETLABS_INJECTION_API_KEY
6-
};
8+
};
9+

0 commit comments

Comments
 (0)