From 4c04419cdeb29591b4e1d2c7908460ff62534d61 Mon Sep 17 00:00:00 2001 From: Johnny Goodnow Date: Wed, 7 Feb 2018 23:50:57 -0800 Subject: [PATCH] Handle 402/403's with current API setup. --- src/Asana/Errors/AsanaError.php | 13 +++++++++++++ src/Asana/Errors/PremiumOnlyError.php | 16 ++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 src/Asana/Errors/PremiumOnlyError.php diff --git a/src/Asana/Errors/AsanaError.php b/src/Asana/Errors/AsanaError.php index 81b4143..046be3c 100644 --- a/src/Asana/Errors/AsanaError.php +++ b/src/Asana/Errors/AsanaError.php @@ -12,6 +12,7 @@ class AsanaError extends \Exception { + const PREMIUM_ONLY_STR = "not available for free"; public function __construct($message, $status, $response) { $this->message = $message; @@ -23,6 +24,16 @@ public static function handleErrorResponse($response) { switch ($response->code) { case ForbiddenError::STATUS: + // Handle 403's with a premium response + try { + foreach ($response->body->errors as $error) { + if (strpos($error->message, self::PREMIUM_ONLY_STR) !== false) { + throw new PremiumOnlyError($response); + } + } + } catch (Exception $e) { + throw new ForbiddenError($response); + } throw new ForbiddenError($response); case InvalidRequestError::STATUS: throw new InvalidRequestError($response); @@ -32,6 +43,8 @@ public static function handleErrorResponse($response) throw new NoAuthorizationError($response); case NotFoundError::STATUS: throw new NotFoundError($response); + case PremiumOnlyError::STATUS: + throw new PremiumOnlyError($response); case RateLimitEnforcedError::STATUS: throw new RateLimitEnforcedError($response); case ServerError::STATUS: diff --git a/src/Asana/Errors/PremiumOnlyError.php b/src/Asana/Errors/PremiumOnlyError.php new file mode 100644 index 0000000..0198d4e --- /dev/null +++ b/src/Asana/Errors/PremiumOnlyError.php @@ -0,0 +1,16 @@ +