fix(GUI): ignore ECONNRESET and ECONNREFUSED when querying S3 (#1415)

Querying S3 to determine the latest available versions might throw
`ECONNRESET` and `ECONNREFUSED`. This commit extends the
`s3Packages.getRemoteVersions()` function to handle these errors and
return no available version if so, like we already do with other similar
HTTP errors.

Change-Type: patch
Changelog-Entry: Fix `ECONNRESET` and `ECONNREFUSED` errors when checking for updates on unstable connections.
Fixes: https://github.com/resin-io/etcher/issues/1396
Fixes: https://github.com/resin-io/etcher/issues/1388
Signed-off-by: Juan Cruz Viotti <jviotti@openmailbox.org>
This commit is contained in:
Juan Cruz Viotti 2017-05-11 21:20:03 -04:00 committed by GitHub
parent babe12cd7b
commit b7f871607e
2 changed files with 50 additions and 0 deletions

View File

@ -148,6 +148,10 @@ exports.getRemoteVersions = _.memoize((bucketUrl) => {
})
.catch({
code: 'ENOTFOUND'
}, {
code: 'ECONNRESET'
}, {
code: 'ECONNREFUSED'
}, {
code: 'ETIMEDOUT'
}, () => {

View File

@ -643,6 +643,52 @@ describe('Shared: s3Packages', function() {
});
describe('given ECONNRESET', function() {
beforeEach(function() {
const error = new Error('ECONNRESET');
error.code = 'ECONNRESET';
this.requestGetAsyncStub = m.sinon.stub(request, 'getAsync');
this.requestGetAsyncStub.returns(Bluebird.reject(error));
});
afterEach(function() {
this.requestGetAsyncStub.restore();
});
it('should resolve an empty array', function(done) {
s3Packages.getRemoteVersions(s3Packages.BUCKET_URL.PRODUCTION).then((versions) => {
m.chai.expect(versions).to.deep.equal([]);
done();
}).catch(done);
});
});
describe('given ECONNREFUSED', function() {
beforeEach(function() {
const error = new Error('ECONNREFUSED');
error.code = 'ECONNREFUSED';
this.requestGetAsyncStub = m.sinon.stub(request, 'getAsync');
this.requestGetAsyncStub.returns(Bluebird.reject(error));
});
afterEach(function() {
this.requestGetAsyncStub.restore();
});
it('should resolve an empty array', function(done) {
s3Packages.getRemoteVersions(s3Packages.BUCKET_URL.PRODUCTION).then((versions) => {
m.chai.expect(versions).to.deep.equal([]);
done();
}).catch(done);
});
});
});
describe('.getLatestVersion()', function() {