Skip to content

Commit

Permalink
Implement distinction for type required in onFailure
Browse files Browse the repository at this point in the history
  • Loading branch information
fredericbarthelet committed Sep 11, 2020
1 parent 9f97e88 commit f295ea1
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions lib/plugins/aws/package/compile/events/stream/index.js
Expand Up @@ -37,17 +37,26 @@ class AwsCompileStreamEvents {
type: 'object',
properties: {
onFailure: {
oneOf: [
anyOf: [
{ $ref: '#/definitions/awsArnString' },
{
type: 'object',
properties: {
arn: { $ref: '#/definitions/awsArn' },
arn: { $ref: '#/definitions/awsArnString' },
type: { enum: ['sns', 'sqs'] },
},
additionalProperties: false,
required: ['arn'],
},
{
type: 'object',
properties: {
arn: { $ref: '#/definitions/awsCfFunction' },
type: { enum: ['sns', 'sqs'] },
},
additionalProperties: false,
required: ['arn', 'type'],
},
],
},
},
Expand Down Expand Up @@ -220,18 +229,6 @@ class AwsCompileStreamEvents {
let OnFailureDestinationArn;

if (typeof event.stream.destinations.onFailure === 'object') {
if (
typeof event.stream.destinations.onFailure.arn !== 'string' &&
!event.stream.destinations.onFailure.type
) {
const errorMessage = [
`Missing "type" property for on failure destination in function "${functionName}"`,
' If the "arn" property on a destination is a complex type (such as Fn::GetAtt)',
' then a "type" must be provided for the destination, either "sns" or,',
' "sqs". Please check the docs for more info.',
].join('');
throw new this.serverless.classes.Error(errorMessage);
}
OnFailureDestinationArn = event.stream.destinations.onFailure.arn;
} else {
OnFailureDestinationArn = event.stream.destinations.onFailure;
Expand Down

0 comments on commit f295ea1

Please sign in to comment.