I have the following login API.
public function login() {
if (Auth::attempt(['email' => request('email'), 'password' => request('password')])) {
$user = Auth::user();
$success['token'] = $user->createToken('MyApp')->accessToken;
$agency = new AgencyResource(Agency::find($user->agency_id));
$success['agency'] = $agency;
return response()->json(['responseCode' => '101', 'responseMessage' => 'Login successful', 'data' => $success], $this->successStatus);
} else {
return response()->json(['responseCode' => '102', 'responseMessage' => 'Invalid username or password', 'data' => null], 401);
}
}
Whenever I check in the postman with wrong credentials I get the following response.
{
"responseCode": "102",
"responseMessage": "Invalid username or password",
"data": null
}
Which is correct. But the same api gives the following response on Android Device not in json format.
Result in Failure:
[Failure: Exception : HTTP Exception 401 Unauthorized]
Question: I need to have response as what is given by postman. Please help
I use laravel 5.5