Skip to content

Commit

Permalink
added checking for new method
Browse files Browse the repository at this point in the history
  • Loading branch information
Roy Hui committed Jan 5, 2018
1 parent 22000b3 commit 9b1dd8b
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions lib/logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,27 +66,29 @@ module.exports = {
// setup the stream filter correctly
return aliasGetAliasFunctionVersion
.then(version => {
return this.provider
.request('CloudWatchLogs',
'describeLogStreams',
params,
this.options.stage,
this.options.region)
.then(reply => {
if (!reply || _.isEmpty(reply.logStreams)) {
throw new this.serverless.classes
.Error('No existing streams for the function alias');
}
const logStreamNames = _.map(
_.filter(reply.logStreams, stream => _.includes(stream.logStreamName, `[${version}]`)),
stream => stream.logStreamName);

if (_.isEmpty(logStreamNames)) {
return BbPromise.reject(new this.serverless.classes
.Error('No existing streams for the latest version of function alias. If you want to view logs of a specific function version, please use --version to specify'));
}
return logStreamNames
});
if (version) {
return this.provider
.request('CloudWatchLogs',
'describeLogStreams',
params,
this.options.stage,
this.options.region)
.then(reply => {
if (!reply || _.isEmpty(reply.logStreams)) {
throw new this.serverless.classes
.Error('No existing streams for the function alias');
}
const logStreamNames = _.map(
_.filter(reply.logStreams, stream => _.includes(stream.logStreamName, `[${version}]`)),
stream => stream.logStreamName);

if (_.isEmpty(logStreamNames)) {
return BbPromise.reject(new this.serverless.classes.Error('No existing streams for the latest version of function alias. If you want to view logs of a specific function version, please use --version to specify'));
}
return logStreamNames;
});
}
return BbPromise.reject(new this.serverless.classes.Error('Function alias not found.'));
});

},
Expand Down

0 comments on commit 9b1dd8b

Please sign in to comment.