/** * Register any other events for your application. * * @param \Illuminate\Contracts\Events\Dispatcher $events * * @return void */ public function boot(DispatcherContract $events) { parent::boot($events); $response = new ResponseBuilder(new JsonResponse()); /* |-------------------------------------------------------------------------- | Events |-------------------------------------------------------------------------- | | These are events used to return custom JSON response when error occurs | using JWT Library. This type of event listening is compatible with | Laravel 4.* that JWT Library currently supports. | */ Event::listen('tymon.jwt.invalid', function ($exception) { throw $exception; }); Event::listen('tymon.jwt.expired', function ($exception) { throw $exception; }); Event::listen('tymon.jwt.absent', function () use($response) { $exception = new TokenAbsentException(); return $response->exception($exception); }); Event::listen('tymon.jwt.user_not_found', function () use($response) { $exception = new TokenInvalidException(); return $response->exception($exception); }); }
/** * Create API Exception response by given Exception. * * @param $exception * @return JsonResponse */ private function apiException($exception) { $response = new ResponseBuilder(new JsonResponse()); return $response->exception($exception); }