私は承認ユーザーのためにAPIを作成しています。Laravel/Lumenの401応答を取得するには?
応答コードがしかし であれば、私はキャッチすることができます私の現在のコードで応答が代わりに私の401応答でエラーメッセージの401の代わりに、200であれば、私はキャッチすることはできません、私はエラーページを受け取ります。
からstatusCodeが200であれば基本的に私はこのメッセージ
を受け取るこれはルーメン
if($input['phone']==$this->phone && $input['password'] == $this->password){
return response()->json([
'redirect_uri' => $redirect_uri,
'token' => $this->token
]);
}
return response()->json([
'redirect_uri' => $redirect_uri,
'errorMsg' => 'User Not found or id psw wrong'
],401);
の私の闊歩サーバであり、これはLaravel
if($response->getStatusCode() == 401){
dd('you are not authorized');
}
if($response->getStatusCode() == 200){
dd('you are authorized');
//Store user credentials on cache
CacheStore::storeUserCredentials(json_decode((string) $response->getBody(), true));
}
の私のモデルであり、しかし、ステータスコードが401の場合、エラーになります。
がどのようにAPIを呼ぶのですか? – Alfa