Skip to content
Permalink
Browse files

test: Update to not rely on side ServerlessError feature

  • Loading branch information
medikoo committed Jan 20, 2020
1 parent 47e005f commit f1cc3a899856a12ed251ea4a0947a331861cd8b3
Showing with 8 additions and 6 deletions.
  1. +2 −2 lib/classes/Variables.test.js
  2. +6 −4 lib/plugins/aws/provider/awsProvider.js
@@ -1229,7 +1229,7 @@ module.exports = {
const awsProvider = new AwsProvider(serverless, options);
const param = '/some/path/to/invalidparam';
const property = `\${ssm:${param}}`;
const error = new serverless.classes.Error(`Parameter ${param} not found.`, 400);
const error = Object.assign(new Error(`Parameter ${param} not found.`), { statusCode: 400 });
const requestStub = sinon
.stub(awsProvider, 'request')
.callsFake(() => BbPromise.reject(error));
@@ -2381,7 +2381,7 @@ module.exports = {
});
});
it('should return undefined if SSM parameter does not exist', () => {
const error = new serverless.classes.Error(`Parameter ${param} not found.`, 400);
const error = Object.assign(new Error(`Parameter ${param} not found.`), { statusCode: 400 });
const requestStub = sinon
.stub(awsProvider, 'request')
.callsFake(() => BbPromise.reject(error));
@@ -240,10 +240,12 @@ class AwsProvider {
f()
// We're resembling if/else logic, therefore single `then` instead of `then`/`catch` pair
.then(resolve, e => {
const { providerError } = e;
if (
numTry < MAX_TRIES &&
e.statusCode !== 403 && // Invalid credentials
((e.providerError && e.providerError.retryable) || e.statusCode === 429)
providerError &&
((providerError.retryable && providerError.statusCode !== 403) ||
providerError.statusCode === 429)
) {
const nextTryNum = numTry + 1;
const jitter = Math.random() * 3000 - 1000;
@@ -317,14 +319,14 @@ class AwsProvider {
userStats.track('user_awsCredentialsNotFound');
// We do not want to trigger the retry mechanism for credential errors
return BbPromise.reject(
Object.assign(new this.serverless.classes.Error(message, err.statusCode), {
Object.assign(new this.serverless.classes.Error(errorMessage), {
providerError: _.assign({}, err, { retryable: false }),
})
);
}

return BbPromise.reject(
Object.assign(new this.serverless.classes.Error(message, err.statusCode), {
Object.assign(new this.serverless.classes.Error(message), {
providerError: err,
})
);

0 comments on commit f1cc3a8

Please sign in to comment.
You can’t perform that action at this time.