Laravel没有捕获异常

时间:2018-04-18 23:39:38

标签: php laravel-5 exception-handling jwt

我试图从包中的中间件中捕获异常:

public function authenticate(Request $request)
{
    $this->checkForToken($request);

    try {
        if (! $this->auth->parseToken()->authenticate()) {
            throw new UnauthorizedHttpException('jwt-auth', 'User not found');
        }
    } catch (JWTException $e) {
        throw new UnauthorizedHttpException('jwt-auth', $e->getMessage(), $e, $e->getCode());
    }
}

我尝试捕获异常处理程序:

public function render($request, Exception $exception)
{
    //dd($exception);
    if ($exception instanceof UnauthorizedHttpException) {

        return response()->json($exception->getMessage(), $exception->getStatusCode());

    } 

    return parent::render($request, $exception);
}    

但根本没有捕获。例外的dd是这样的:

UnauthorizedHttpException {#231 ▼
-statusCode: 401
-headers: array:1 [▶]
#message: "Token has expired"
#code: 0
#file: "/home/vagrant/codementor/vendor/tymon/jwt- auth/src/Http/Middleware/BaseMiddleware.php"
#line: 74
-previous: TokenExpiredException {#237 ▶}
trace: {▶}
}

0 个答案:

没有答案