From a6088e64f5bd712d8ea3aa6c511a44bd608f18c6 Mon Sep 17 00:00:00 2001 From: Philipp Tkachev Date: Fri, 13 Oct 2017 15:27:03 -0400 Subject: [PATCH] Improve error handling --- src/Client.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Client.php b/src/Client.php index 8bc5559..3340110 100644 --- a/src/Client.php +++ b/src/Client.php @@ -156,7 +156,7 @@ public function getAccessToken($code = '') $requestException->getMessage(), $requestException->getCode(), $requestException, - isset($json['message']) ? $json['message'] : null + static::extractErrorDescription($json) ); throw $lnException; } @@ -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