Skip to content

Commit

Permalink
Client::newMemberSessionFromCredentials() returns null instead of thr…
Browse files Browse the repository at this point in the history
…owing an Exception when invalid credentials
  • Loading branch information
PGBI committed May 30, 2016
1 parent 2785c81 commit 6273573
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
28 changes: 18 additions & 10 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,27 @@ public function newMemberSessionFromCode($code)
/**
* @param $username
* @param $password
* @return Session
* @return Session|null
*/
public function newMemberSessionFromCredentials($username, $password)
{
$response = $this->request('POST', '/oauth2/auth', null, [
'form_params' => [
'grant_type' => 'password',
'client_id' => $this->client_id,
'client_secret' => $this->client_secret,
'username' => $username,
'password' => $password
]
]);
try {
$response = $this->request('POST', '/oauth2/auth', null, [
'form_params' => [
'grant_type' => 'password',
'client_id' => $this->client_id,
'client_secret' => $this->client_secret,
'username' => $username,
'password' => $password
]
]);
} catch (APIResponseException $e) {
$response = $e->getResponseData();
if (isset($response->error) && $response->error == 'Invalid user credentials') {
return null;
}
throw $e;
}
return new Session($response);
}

Expand Down
1 change: 0 additions & 1 deletion src/Exceptions/APIResponseException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Classy\Exceptions;


use GuzzleHttp\Exception\BadResponseException;

class APIResponseException extends \Exception
Expand Down

0 comments on commit 6273573

Please sign in to comment.