I am writing an api for authorize users .
With my current code I can catch if response code is 200 however I cannot catch if the response is 401 instead of 200. Instead of an error message with my 401 response, I recieve error page.
this is my swagger server in Lumen
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);
and this is my model in 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));
}
basically if statuscode is 200 I recieve this message
But if status code is 401 it gives error.