New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default to error code if message is non-existent #4794

Merged
merged 3 commits into from Jan 24, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+77 −1
Diff settings

Always

Just for now

@@ -275,7 +275,7 @@ class AwsProvider {
req.send(cb); req.send(cb);
}); });
return promise.catch(err => { return promise.catch(err => {
let message = err.message; let message = err.message !== null ? err.message : err.code;
if (err.message === 'Missing credentials in config') { if (err.message === 'Missing credentials in config') {
const errorMessage = [ const errorMessage = [
'AWS provider credentials not found.', 'AWS provider credentials not found.',
@@ -452,6 +452,82 @@ describe('AwsProvider', () => {
.catch(() => done()); .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) => { it('should return ref to docs for missing credentials', (done) => {
const error = { const error = {
statusCode: 403, statusCode: 403,
ProTip! Use n and p to navigate between commits in a pull request.