mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-16 16:58:38 +01:00
Use exceptions for S3 error messages
Summary: Right now, the "SimpleEmailService" class uses trigger_error() to communicate error messages. This means they get lost in the error logs and aren't visible in the MetaMTA interface. Provide a flag to strengthen them into exceptions, instead. (I've attempted to emulate the prevailing style so I can offer this upstream.) Test Plan: Faked an error condition and got a detailed stack trace in MetaMTA instead of an empty "Message" field. Reviewed By: jungejason Reviewers: hunterbridges, codeblock, jungejason, tuomaspelkonen, aran CC: aran, jungejason Differential Revision: 783
This commit is contained in:
parent
c7e1fa626d
commit
d064c6efa8
2 changed files with 24 additions and 3 deletions
26
externals/amazon-ses/ses.php
vendored
26
externals/amazon-ses/ses.php
vendored
|
@ -66,6 +66,12 @@ class SimpleEmailService
|
||||||
public function verifyPeer() { return $this->__verifyPeer; }
|
public function verifyPeer() { return $this->__verifyPeer; }
|
||||||
public function enableVerifyPeer($enable = true) { $this->__verifyPeer = $enable; }
|
public function enableVerifyPeer($enable = true) { $this->__verifyPeer = $enable; }
|
||||||
|
|
||||||
|
// If you use exceptions, errors will be communicated by throwing a
|
||||||
|
// SimpleEmailServiceException. By default, they will be trigger_error()'d.
|
||||||
|
protected $__useExceptions = 0;
|
||||||
|
public function useExceptions() { return $this->__useExceptions; }
|
||||||
|
public function enableUseExceptions($enable = true) { $this->__useExceptions = $enable; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
|
@ -94,7 +100,7 @@ class SimpleEmailService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lists the email addresses that have been verified and can be used as the 'From' address
|
* Lists the email addresses that have been verified and can be used as the 'From' address
|
||||||
*
|
*
|
||||||
* @return An array containing two items: a list of verified email addresses, and the request id.
|
* @return An array containing two items: a list of verified email addresses, and the request id.
|
||||||
*/
|
*/
|
||||||
public function listVerifiedEmailAddresses() {
|
public function listVerifiedEmailAddresses() {
|
||||||
|
@ -368,16 +374,21 @@ class SimpleEmailService
|
||||||
public function __triggerError($functionname, $error)
|
public function __triggerError($functionname, $error)
|
||||||
{
|
{
|
||||||
if($error == false) {
|
if($error == false) {
|
||||||
trigger_error(sprintf("SimpleEmailService::%s(): Encountered an error, but no description given", $functionname), E_USER_WARNING);
|
$message = sprintf("SimpleEmailService::%s(): Encountered an error, but no description given", $functionname);
|
||||||
}
|
}
|
||||||
else if(isset($error['curl']) && $error['curl'])
|
else if(isset($error['curl']) && $error['curl'])
|
||||||
{
|
{
|
||||||
trigger_error(sprintf("SimpleEmailService::%s(): %s %s", $functionname, $error['code'], $error['message']), E_USER_WARNING);
|
$message = sprintf("SimpleEmailService::%s(): %s %s", $functionname, $error['code'], $error['message']);
|
||||||
}
|
}
|
||||||
else if(isset($error['Error']))
|
else if(isset($error['Error']))
|
||||||
{
|
{
|
||||||
$e = $error['Error'];
|
$e = $error['Error'];
|
||||||
$message = sprintf("SimpleEmailService::%s(): %s - %s: %s\nRequest Id: %s\n", $functionname, $e['Type'], $e['Code'], $e['Message'], $error['RequestId']);
|
$message = sprintf("SimpleEmailService::%s(): %s - %s: %s\nRequest Id: %s\n", $functionname, $e['Type'], $e['Code'], $e['Message'], $error['RequestId']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->useExceptions()) {
|
||||||
|
throw new SimpleEmailServiceException($message);
|
||||||
|
} else {
|
||||||
trigger_error($message, E_USER_WARNING);
|
trigger_error($message, E_USER_WARNING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -720,3 +731,12 @@ final class SimpleEmailServiceMessage {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Thrown by SimpleEmailService when errors occur if you call
|
||||||
|
* enableUseExceptions(true).
|
||||||
|
*/
|
||||||
|
final class SimpleEmailServiceException extends Exception {
|
||||||
|
|
||||||
|
}
|
|
@ -42,6 +42,7 @@ class PhabricatorMailImplementationAmazonSESAdapter
|
||||||
require_once $root.'/externals/amazon-ses/ses.php';
|
require_once $root.'/externals/amazon-ses/ses.php';
|
||||||
|
|
||||||
$service = newv('SimpleEmailService', array($key, $secret));
|
$service = newv('SimpleEmailService', array($key, $secret));
|
||||||
|
$service->enableUseExceptions(true);
|
||||||
return $service->sendRawEmail($body);
|
return $service->sendRawEmail($body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue