更改 Json 护照中的回复
Change Json response in passport
你能告诉我如何更改 JSON 对带有错误 api 令牌的请求的响应。
我的意思是
{
"message": "Unauthenticated."
}
我想这样做
{
"error": true,
"message": "Unauthenticated.",
}
我应该在哪里更改它?谢谢
在您项目的 app/Exceptions/Handler.php
文件中有一个名为 render()
的函数。在该函数内添加以下代码块:
if($exception instanceof \Illuminate\Auth\AuthenticationException){
return response()->json(['error' => true, 'message' => 'Unauthenticated.'], 401);
}
你能告诉我如何更改 JSON 对带有错误 api 令牌的请求的响应。
我的意思是
{
"message": "Unauthenticated."
}
我想这样做
{
"error": true,
"message": "Unauthenticated.",
}
我应该在哪里更改它?谢谢
在您项目的 app/Exceptions/Handler.php
文件中有一个名为 render()
的函数。在该函数内添加以下代码块:
if($exception instanceof \Illuminate\Auth\AuthenticationException){
return response()->json(['error' => true, 'message' => 'Unauthenticated.'], 401);
}