Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Commit

Permalink
fix(rate limit): check statusCode instead of error message (#273)
Browse files Browse the repository at this point in the history
linked with https:/algolia/algoliasearch-client-
js/commit/e105b9bc89d826224006c0e980e3966162265b7b
  • Loading branch information
vvo authored Jul 6, 2016
1 parent 6828f68 commit ed52234
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"eslint-config-algolia": "^4.2.0",
"eslint-plugin-algolia": "^1.5.0",
"eslint-plugin-react": "^3.5.1",
"jest-cli": "^13.0.0",
"jest-cli": "^13.1.1",
"json": "^9.0.4",
"mversion": "^1.10.1",
"node-sass": "^3.8.0",
Expand All @@ -55,7 +55,7 @@
"webpack": "^1.13.1"
},
"dependencies": {
"algoliasearch": "^3.16.0",
"algoliasearch": "^3.17.0",
"autocomplete.js": "^0.20.1",
"events": "^1.1.1",
"insert-css": "^1.0.0"
Expand Down
2 changes: 1 addition & 1 deletion src/createAutocompleteSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default function createAutocompleteSource({
)
.then(cb)
.catch(e => {
if (e.message === 'Too many requests') {
if (e.statusCode === 429) {
onRateLimitReached();
return;
}
Expand Down
3 changes: 2 additions & 1 deletion src/createAutocompleteSource.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ describe('createAutocompleteSource', () => {
});

it('supports onRateLimitReached option', () => {
const error = new Error('Too many requests');
const error = new Error('Some error message');
error.statusCode = 429;
const searchFn = jest.fn(() => Promise.reject(error));
const onRateLimitReached = jest.fn();
algoliasearch.__setSearchStub(searchFn);
Expand Down

0 comments on commit ed52234

Please sign in to comment.