答案 0 :(得分:2)
我自己回答,将配置添加到guzzle 'http_errors' => false
会将错误返回给json。
public function loginapi(Request $request)
{
$username = $request->username;
$password = $request->password;
$http = new Client;
$response = $http->post('http://restapi.dev/oauth/token', [
'form_params' => [
'grant_type' => 'password',
'client_id' => 3,
'client_secret' => 'Lh66IODOP4pZHF676xZA8ghQiIt9OepqYHVzFEIN',
'username' => $username,
'password' => $password,
'scope' => '',
],
'http_errors' => false //add this to return errors in json
]);
return json_decode((string) $response->getBody(), true);
}