Skip to content

Commit

Permalink
Return a message when a 429 http response is received (#115)
Browse files Browse the repository at this point in the history
This adds a case for handling 429 responses from Simperium, which has an empty response body, and adds a response text which can then be used to handle this error specifically.
  • Loading branch information
sandymcfadden committed Oct 1, 2021
1 parent cc5885d commit bd7ba06
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
4 changes: 4 additions & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.1.4

- Adds a message response when receiving a 429 HTTP error [#115](https://github.com/simperium/node-simperium/pull/115)

## 1.1.3

- Fixes a sync issue by reverting the changes from PR #101 [#114](https://github.com/simperium/node-simperium/pull/114)
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simperium",
"version": "1.1.3",
"version": "1.1.4",
"description": "A simperium client for node.js",
"main": "./lib/simperium/index.js",
"browser": {
Expand Down
7 changes: 6 additions & 1 deletion src/simperium/http-request.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ export default function(
xhr.open( 'POST', url );
xhr.setRequestHeader( 'X-Simperium-API-Key', apiKey );

xhr.onload = () => resolve( xhr.responseText );
xhr.onload = () => {
if ( xhr.status === 429 && xhr.responseText === '' ) {
return resolve('too many requests');
}
resolve(xhr.responseText);
};
xhr.onerror = () => reject();

xhr.send( body );
Expand Down

0 comments on commit bd7ba06

Please sign in to comment.