Permalink
Browse files

Added check for 'token_expired' message in 401 response from Cascade.

  • Loading branch information...
1 parent d4da24a commit a6fa6f530b70074711b5b0094654a17810e87200 @michaelcurtis committed Mar 24, 2010
Showing with 13 additions and 3 deletions.
  1. +13 −3 ymclient.php
View
16 ymclient.php
@@ -47,14 +47,24 @@ function __call($method, $arguments) {
throw new YMClientException("Empty response", 0, "The Ymail webservice returned an empty response");
}
+ $response = json_decode($rawresponse);
+
// Cascade returned an "unauthorized" response. Try to refresh the access token
if($responseCode == 401) {
- $tok = $this->__oauth_refresh_access_token($tok);
- $this->oaRefreshedToken = $tok;
+
+ // The token expired, attempt to refresh it
+ if(isset($response->error->description) && preg_match("/token_expired/", $response->error->description)) {
+ $tok = $this->__oauth_refresh_access_token($tok);
+ $this->oaRefreshedToken = $tok;
+ }
+
+ // Some other error occured. Forward along info about it.
+ else {
+ throw new YMClientException("Ymail request failed", $responseCode, $response);
+ }
}
else {
- $response = json_decode($rawresponse);
return $response->result;
}
}

0 comments on commit a6fa6f5

Please sign in to comment.