/**
  * 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);
     });
 }
Exemplo n.º 2
0
 /**
  * Overwrites default response method on FormRequest class. The only change is that
  * JSON response have custom structure.
  *
  * @param array $errors
  *
  * @return $this|JsonResponse
  */
 public function response(array $errors)
 {
     if ($this->ajax() || $this->wantsJson()) {
         $response = new ResponseBuilder(new JsonResponse());
         return $response->error(ResponseCode::UNPROCESSABLE_ENTITY, $errors);
     }
     return $this->redirector->to($this->getRedirectUrl())->withInput($this->except($this->dontFlash))->withErrors($errors, $this->errorBag);
 }
Exemplo n.º 3
0
 /**
  * Create API Exception response by given Exception.
  *
  * @param $exception
  * @return JsonResponse
  */
 private function apiException($exception)
 {
     $response = new ResponseBuilder(new JsonResponse());
     return $response->exception($exception);
 }