Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[lib] Provide default error message when server does not respond.

  • Loading branch information...
commit 45e3d67a3903c2ec7fe024dcf109035ac263944d 1 parent d52a31a
@mwbrooks mwbrooks authored
View
3  lib/api.js
@@ -206,6 +206,9 @@ module.exports = function(options) {
args.callback(e);
}
else if (res.statusCode !== 200 && res.statusCode !== 201 && res.statusCode !== 202) {
+ // provide a default message when none is provided
+ body = body || 'server returned status code ' + res.statusCode;
+
// eror in response
args.callback(new Error(body));
}
View
2  lib/auth.js
@@ -63,6 +63,8 @@ module.exports = function(options, callback) {
// failed response
if (response.statusCode !== 200) {
+ // provide a default message when none is provided
+ body = body || 'server returned status code ' + response.statusCode;
callback(new Error(body));
return;
}
View
19 spec/api.spec.js
@@ -230,13 +230,14 @@ describe('new API', function() {
describe('failed api response', function() {
beforeEach(function() {
spyOn(request, 'send').andCallFake(function(url, opts, callback) {
- callback(null, { statusCode: 404 }, 'Page not found');
+ callback(null, { statusCode: 404 }, 'page not found');
});
});
it('should trigger callback with an error', function(done) {
api('/apps', function(e, data) {
expect(e).toEqual(jasmine.any(Error));
+ expect(e.message).toEqual('page not found');
done();
});
});
@@ -247,6 +248,22 @@ describe('new API', function() {
done();
});
});
+
+ describe('when no error body provided', function() {
+ beforeEach(function() {
+ request.send.andCallFake(function(uri, opts, callback) {
+ callback(null, { statusCode: 501 }, '');
+ });
+ });
+
+ it('should provide default error message', function(done) {
+ api('/apps', function(e, data) {
+ expect(e).toEqual(jasmine.any(Error));
+ expect(e.message).toMatch('server returned');
+ done();
+ });
+ });
+ });
});
describe('failed api data', function() {
View
19 spec/phonegap-build-api.spec.js
@@ -99,13 +99,14 @@ describe('phonegap-build-api', function() {
describe('failed authentication response', function() {
beforeEach(function() {
spyOn(request, 'post').andCallFake(function(uri, opts, callback) {
- callback(null, { statusCode: 404 }, '');
+ callback(null, { statusCode: 404 }, 'page not found');
});
});
it('should trigger callback with an error', function(done) {
client.auth(options, function(e, api) {
expect(e).toEqual(jasmine.any(Error));
+ expect(e.message).toEqual('page not found');
done();
});
});
@@ -116,6 +117,22 @@ describe('phonegap-build-api', function() {
done();
});
});
+
+ describe('when no error body provided', function() {
+ beforeEach(function() {
+ request.post.andCallFake(function(uri, opts, callback) {
+ callback(null, { statusCode: 501 }, '');
+ });
+ });
+
+ it('should provide default error message', function(done) {
+ client.auth(options, function(e, api) {
+ expect(e).toEqual(jasmine.any(Error));
+ expect(e.message).toMatch('server returned');
+ done();
+ });
+ });
+ });
});
describe('failed authentication credentials', function() {
Please sign in to comment.
Something went wrong with that request. Please try again.