File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -213,7 +213,13 @@ class ScmRouter extends Scm {
213213 if ( ! scm ) {
214214 logger . info ( 'Webhook does not match any expected events or actions.' ) ;
215215
216- return null ;
216+ const err = new Error (
217+ 'Cannot parse this webhook. Please ensure that the signature is correct or that this SCM is supported.'
218+ ) ;
219+
220+ err . statusCode = 400 ;
221+
222+ return Promise . reject ( err ) ;
217223 }
218224
219225 return scm . parseHook ( headers , payload ) ;
Original file line number Diff line number Diff line change @@ -614,6 +614,25 @@ describe('index test', () => {
614614 assert . calledOnce ( exampleScm . parseHook ) ;
615615 assert . calledWith ( exampleScm . parseHook , headers , payload ) ;
616616 } ) ) ;
617+
618+ it ( 'rejects error when all scm cannot parse the webhook' , ( ) => {
619+ scmGithub . canHandleWebhook . resolves ( false ) ;
620+ scmGitlab . canHandleWebhook . resolves ( false ) ;
621+ exampleScm . canHandleWebhook . resolves ( false ) ;
622+
623+ return scm
624+ . _parseHook ( headers , payload )
625+ . then ( ( ) => {
626+ assert . fail ( 'This should not fail the tests' ) ;
627+ } )
628+ . catch ( err => {
629+ assert . include ( err . message , 'Cannot parse this webhook' ) ;
630+ assert . strictEqual ( err . statusCode , 400 ) ;
631+ assert . notCalled ( scmGithub . parseHook ) ;
632+ assert . notCalled ( scmGitlab . parseHook ) ;
633+ assert . notCalled ( exampleScm . parseHook ) ;
634+ } ) ;
635+ } ) ;
617636 } ) ;
618637
619638 describe ( '_getCheckoutCommand' , ( ) => {
You can’t perform that action at this time.
0 commit comments