Skip to content

Commit

Permalink
Accept ZERO_RESULTS as a successful response.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenfarrar committed Nov 9, 2016
1 parent 99c144d commit 2c9be2d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/internal/make-api-call.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ exports.inject = function(options) {
var task =
Task.race([timeoutTask, requestTask])
.thenDo(function(response) {
if (response.status === 200 && response.json.status === 'OK') {
if (response.status === 200 && (
response.json.status === 'OK' ||
response.json.status === 'ZERO_RESULTS')) {
return Task.withValue(response);
} else {
return Task.withError(response);
Expand Down
33 changes: 33 additions & 0 deletions spec/unit/index-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,24 @@ describe('index.js:', function() {
.then(done, fail);
});

it('delivers ZERO_RESULTS as success', function(done) {
createClient({
Promise: Promise,
makeUrlRequest: function(url, onSuccess) {
onSuccess({status: 200, json: {status: 'ZERO_RESULTS'}});
}
})
.geocode({address: 'Sydney Opera House'})
.asPromise()
.then(function(response) {
expect(response).toEqual({
status: 200,
json: {status: 'ZERO_RESULTS'}
});
})
.then(done, fail);
});

it('delivers errors', function(done) {
createClient({
Promise: Promise,
Expand All @@ -276,6 +294,21 @@ describe('index.js:', function() {
})
});

it('delivers REQUEST_DENIED as an error', function(done) {
createClient({
Promise: Promise,
makeUrlRequest: function(url, onSuccess) {
onSuccess({status: 200, json: {status: 'REQUEST_DENIED'}});
}
})
.geocode({address: 'Sydney Opera House'})
.asPromise()
.then(fail, function(error) {
expect(error.json).toEqual({status: 'REQUEST_DENIED'});
done();
})
});

it('throws validation errors', function() {
expect(function() {
createClient({Promise: Promise, makeUrlRequest: requestAndSucceed})
Expand Down

0 comments on commit 2c9be2d

Please sign in to comment.