vendredi 30 octobre 2015

How to catch global exceptions in laravel 5 genarated by the EvanDarwin/Laravel-JSend pacakge?

I am working on a RESTful application using Laravel 5 and I am trying to catch exceptions and generate an appropriate response. I am also using the EvanDarwin/Laravel-JSend package so that all the API responses are in JSend JSON format.

Right now I am trying to catch the TokenExpiredException which arises when the given token is expired of course. So I tried this in the Handler.php:

if($e instanceof TokenExpiredException)
{
    return jsend()->error()
          ->message("Token Expired")
          ->code(403)
          ->data([null])
          ->get();
}

But I am still not able to catch this exception and give back a JSON response. Although I am able to do this for other exceptions like:

if ($e instanceof ModelNotFoundException) {
    $e = new NotFoundHttpException($e->getMessage(), $e);

    return jsend()->error()
              ->message("404 Model Not Found")
              ->data([null])
              ->get();
}

And:

if ($this->isHttpException($e))
{       
    if($e instanceof NotFoundHttpException)
    {
        return jsend()->error()
              ->message("404 Route Not Found")
              ->data([null])
              ->get();
    }
    return $this->renderHttpException($e);
}

How to handle other exceptions in Laravel?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1Oc4Fdi
via IFTTT

Aucun commentaire:

Enregistrer un commentaire