Skip to content

Commit

Permalink
Merge pull request #167 from aoberoi/error-for-invalid-action-constra…
Browse files Browse the repository at this point in the history
…ints

fail early for unknown action constraints
  • Loading branch information
shaydewael authored Apr 24, 2019
2 parents 8f9245f + 7fb9dbd commit a0483b7
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,16 @@ export default class App {
(typeof actionIdOrConstraints === 'string' || util.types.isRegExp(actionIdOrConstraints)) ?
{ action_id: actionIdOrConstraints } : actionIdOrConstraints;

// Fail early if the constraints contain invalid keys
const unknownConstraintKeys = Object.keys(constraints)
.filter(k => (k !== 'action_id' && k !== 'block_id' && k !== 'callback_id'));
if (unknownConstraintKeys.length > 0) {
this.logger.error(
`Action listener cannot be attached using unknown constraint keys: ${unknownConstraintKeys.join(', ')}`,
);
return;
}

this.listeners.push(
[onlyActions, matchConstraints(constraints), ...listeners] as Middleware<AnyMiddlewareArgs>[],
);
Expand Down

0 comments on commit a0483b7

Please sign in to comment.