Unverified Commit 36a7d5d0 authored by Côme Chilliet's avatar Côme Chilliet
Browse files

:ambulance: fix(partage) Improve error handling for GetAccount

We need to find out error codes for non-existing account to explicitely
 ignore only those. Renater PARTAGE API documentation does not specify
 them.

issue #6104
No related merge requests found
Showing with 22 additions and 14 deletions
+22 -14
...@@ -117,11 +117,10 @@ class mailMethodRenaterPartage extends mailMethod ...@@ -117,11 +117,10 @@ class mailMethodRenaterPartage extends mailMethod
if (!isset($response['Response']['status'])) { if (!isset($response['Response']['status'])) {
throw new MailMethodError(htmlescape(_('Partage API answer malformated'))); throw new MailMethodError(htmlescape(_('Partage API answer malformated')));
} elseif ($response['Response']['status'] != 0) { } elseif ($response['Response']['status'] != 0) {
/* FIXME - We need to ignore errors when doing GetAccount, propably by looking at status code */
if (isset($response['Response']['message'])) { if (isset($response['Response']['message'])) {
throw new MailMethodError(htmlescape(sprintf(_('Partage API Auth failed: %s'), $response['Response']['message']))); throw new MailMethodError(htmlescape(sprintf(_('Partage API Auth failed: %s'), $response['Response']['message'])), $response['Response']['status']);
} else { } else {
throw new MailMethodError(htmlescape(_('Partage API Auth failed with no error message'))); throw new MailMethodError(htmlescape(_('Partage API Auth failed with no error message')), $response['Response']['status']);
} }
} }
...@@ -197,17 +196,26 @@ class mailMethodRenaterPartage extends mailMethod ...@@ -197,17 +196,26 @@ class mailMethodRenaterPartage extends mailMethod
$command = 'GetGroup'; $command = 'GetGroup';
$answerkey = 'group'; $answerkey = 'group';
} }
$answer = $this->query($command, ['name' => $this->account_id]); try {
if (isset($answer['Response'][$answerkey])) { $answer = $this->query($command, ['name' => $this->account_id]);
$this->cachedAccount = [ if (isset($answer['Response'][$answerkey])) {
'account' => $answer['Response'][$answerkey], $this->cachedAccount = [
'id' => $this->account_id, 'account' => $answer['Response'][$answerkey],
'time' => time() 'id' => $this->account_id,
]; 'time' => time()
$this->cleanCachedAccountArrays(); ];
return TRUE; $this->cleanCachedAccountArrays();
} else { return TRUE;
return FALSE; } else {
return FALSE;
}
} catch (MailMethodError $e) {
if ($e->getCode() > 0) {
/* FIXME - We should look at code to only silence account/group not found */
return FALSE;
} else {
throw $e;
}
} }
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment