为什么它没有按照给定的方式呈现?AccessDeniedHttpException 以外的其他类型异常都正常工作。
App/Exceptions/Handler.php
401 工作得很好,但 403 做原始渲染。
有什么解决方案吗?
App/Exceptions/Handler.php
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException as AccessDeniedHttpException;
...
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $exception)
...
// 403 Forbidden
if ($exception instanceof AccessDeniedHttpException)
{
return response()->json([
'code' => 403,
'message' => 'This action is unauthorized1.',
],403);
}
// 401 Unauthorized
if ($exception instanceof AuthenticationException)
{
return response()->json([
'code' => 401,
'message' => 'Unauthenticated error.',
], 401);
}
401 工作得很好,但 403 做原始渲染。
有什么解决方案吗?