Skip to content

Commit

Permalink
Merge pull request #4794 from drexler/default-error-message
Browse files Browse the repository at this point in the history
Default to error code if message is non-existent
  • Loading branch information
pmuens committed Jan 24, 2019
2 parents dfb36b8 + ecaa6d8 commit 0aa672e
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/plugins/aws/provider/awsProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ class AwsProvider {
req.send(cb);
});
return promise.catch(err => {
let message = err.message;
let message = err.message !== null ? err.message : err.code;
if (err.message === 'Missing credentials in config') {
const errorMessage = [
'AWS provider credentials not found.',
Expand Down
76 changes: 76 additions & 0 deletions lib/plugins/aws/provider/awsProvider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,82 @@ describe('AwsProvider', () => {
.catch(() => done());
});

it('should use error message if it exists', (done) => {
const awsErrorResponse = {
message: 'Something went wrong...',
code: 'Forbidden',
region: null,
time: '2019-01-24T00:29:01.780Z',
requestId: 'DAF12C1111A62C6',
extendedRequestId: '1OnSExiLCOsKrsdjjyds31w=',
statusCode: 403,
retryable: false,
retryDelay: 13.433158364430508,
};

class FakeS3 {
constructor(credentials) {
this.credentials = credentials;
}

error() {
return {
send(cb) {
cb(awsErrorResponse);
},
};
}
}
awsProvider.sdk = {
S3: FakeS3,
};
awsProvider.request('S3', 'error', {})
.then(() => done('Should not succeed'))
.catch((err) => {
expect(err.message).to.eql(awsErrorResponse.message);
done();
})
.catch(done);
});

it('should default to error code if error message is non-existent', (done) => {
const awsErrorResponse = {
message: null,
code: 'Forbidden',
region: null,
time: '2019-01-24T00:29:01.780Z',
requestId: 'DAF12C1111A62C6',
extendedRequestId: '1OnSExiLCOsKrsdjjyds31w=',
statusCode: 403,
retryable: false,
retryDelay: 13.433158364430508,
};

class FakeS3 {
constructor(credentials) {
this.credentials = credentials;
}

error() {
return {
send(cb) {
cb(awsErrorResponse);
},
};
}
}
awsProvider.sdk = {
S3: FakeS3,
};
awsProvider.request('S3', 'error', {})
.then(() => done('Should not succeed'))
.catch((err) => {
expect(err.message).to.eql(awsErrorResponse.code);
done();
})
.catch(done);
});

it('should return ref to docs for missing credentials', (done) => {
const error = {
statusCode: 403,
Expand Down

0 comments on commit 0aa672e

Please sign in to comment.