如何修改laravel sanctum 令牌验证 未登录返回的响应

laravel sanctum 令牌验证 未登录返回的响应:
状态码 401

{
    "message": "Unauthenticated."
}

我想知道这个响应怎么修改或配置
希望看到的大神指点一二

《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
最佳答案

在 namespace App\Exceptions\Handler;加入下面代码 public function register() {

    $this->renderable(function (\Illuminate\Auth\AuthenticationException $e, $request) {
        return response()->json([
            'error_code' => 401,
            'data' => (object) [],
            'error_data' => (object) [],
            'message' => 'Unauthenticated'
        ], 401);
    });
}
3年前 评论
Ahmatjan 2年前
讨论数量: 5

佬大的这篇教程可以参考下!

https://learnku.com/laravel/t/43077

3年前 评论

在 namespace App\Exceptions\Handler;加入下面代码 public function register() {

    $this->renderable(function (\Illuminate\Auth\AuthenticationException $e, $request) {
        return response()->json([
            'error_code' => 401,
            'data' => (object) [],
            'error_data' => (object) [],
            'message' => 'Unauthenticated'
        ], 401);
    });
}
3年前 评论
Ahmatjan 2年前
chowjiawei
public function report(Throwable $exception)
    {
        if ($exception instanceof AuthenticationException) {
            if ($exception->getMessage()=='Unauthenticated.') {
                throw new UnauthorizedHttpException('Unauthenticated', "账号未登录,请前往登录");
            }
        }

        parent::report($exception);
    }
3年前 评论
chowjiawei (作者) 3年前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!