Skip to content

Commit

Permalink
Improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
zoonman committed Oct 13, 2017
1 parent 620eacb commit a6088e6
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public function getAccessToken($code = '')
$requestException->getMessage(),
$requestException->getCode(),
$requestException,
isset($json['message']) ? $json['message'] : null
static::extractErrorDescription($json)
);
throw $lnException;
}
Expand Down Expand Up @@ -368,13 +368,24 @@ public function api($endpoint, array $params = array(), $method = Method::GET)
$requestException->getMessage(),
$requestException->getCode(),
$requestException,
isset($json['message']) ? $json['message'] : null
static::extractErrorDescription($json)
);
throw $lnException;
}
return self::responseToArray($response);
}

private static function extractErrorDescription($json)
{
if (isset($json['error_description'])) {
return $json['error_description'];
} elseif (isset($json['message'])) {
return $json['message'];
} else {
return null;
}
}

/**
* Make API call to LinkedIn using GET method
* @param string $endpoint
Expand Down

0 comments on commit a6088e6

Please sign in to comment.