Skip to content

Commit 9b1dd8b

Browse files
author
Roy Hui
committed
added checking for new method
1 parent 22000b3 commit 9b1dd8b

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

lib/logs.js

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,27 +66,29 @@ module.exports = {
6666
// setup the stream filter correctly
6767
return aliasGetAliasFunctionVersion
6868
.then(version => {
69-
return this.provider
70-
.request('CloudWatchLogs',
71-
'describeLogStreams',
72-
params,
73-
this.options.stage,
74-
this.options.region)
75-
.then(reply => {
76-
if (!reply || _.isEmpty(reply.logStreams)) {
77-
throw new this.serverless.classes
78-
.Error('No existing streams for the function alias');
79-
}
80-
const logStreamNames = _.map(
81-
_.filter(reply.logStreams, stream => _.includes(stream.logStreamName, `[${version}]`)),
82-
stream => stream.logStreamName);
83-
84-
if (_.isEmpty(logStreamNames)) {
85-
return BbPromise.reject(new this.serverless.classes
86-
.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'));
87-
}
88-
return logStreamNames
89-
});
69+
if (version) {
70+
return this.provider
71+
.request('CloudWatchLogs',
72+
'describeLogStreams',
73+
params,
74+
this.options.stage,
75+
this.options.region)
76+
.then(reply => {
77+
if (!reply || _.isEmpty(reply.logStreams)) {
78+
throw new this.serverless.classes
79+
.Error('No existing streams for the function alias');
80+
}
81+
const logStreamNames = _.map(
82+
_.filter(reply.logStreams, stream => _.includes(stream.logStreamName, `[${version}]`)),
83+
stream => stream.logStreamName);
84+
85+
if (_.isEmpty(logStreamNames)) {
86+
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'));
87+
}
88+
return logStreamNames;
89+
});
90+
}
91+
return BbPromise.reject(new this.serverless.classes.Error('Function alias not found.'));
9092
});
9193

9294
},

0 commit comments

Comments
 (0)