33namespace AppBundle \Controller ;
44
55use AppBundle \Event \GitHubEvent ;
6+ use AppBundle \Exception \GitHubException ;
67use Sensio \Bundle \FrameworkExtraBundle \Configuration \Method ;
78use Sensio \Bundle \FrameworkExtraBundle \Configuration \Route ;
89use Symfony \Bundle \FrameworkBundle \Controller \Controller ;
@@ -19,12 +20,12 @@ public function githubAction(Request $request)
1920 {
2021 $ data = json_decode ($ request ->getContent (), true );
2122 if (null === $ data ) {
22- throw new \ Exception ('Invalid JSON body! ' );
23+ throw new GitHubException ('Invalid JSON body! ' );
2324 }
2425
2526 $ repository = isset ($ data ['repository ' ]['full_name ' ]) ? $ data ['repository ' ]['full_name ' ] : null ;
2627 if (empty ($ repository )) {
27- throw new \ Exception ('No repository name! ' );
28+ throw new GitHubException ('No repository name! ' );
2829 }
2930
3031 $ listener = $ this ->get ('app.github.listener_factory ' )->createFromRepository ($ repository );
@@ -35,7 +36,11 @@ public function githubAction(Request $request)
3536 $ event = new GitHubEvent ($ data );
3637 $ eventName = $ request ->headers ->get ('X-Github-Event ' );
3738
38- $ dispatcher ->dispatch ('github. ' .$ eventName , $ event );
39+ try {
40+ $ dispatcher ->dispatch ('github. ' .$ eventName , $ event );
41+ } catch (\Exception $ e ) {
42+ throw new GitHubException (sprintf ('Failed dispatching "%s" event for "%s" repository. ' , $ eventName , $ repository ), 0 , $ e );
43+ }
3944
4045 $ responseData = $ event ->getResponseData ();
4146
0 commit comments