Eileen has uploaded a new change for review.
https://gerrit.wikimedia.org/r/319757
Change subject: Alter WMFException to permit us to present a simpler error for
users.
......................................................................
Alter WMFException to permit us to present a simpler error for users.
Currently the debug is being passed in, which is fine except when we want to
present the message to users.
Bug: T88460
Change-Id: Icd69c23dd4387aff720cdc9d6b0e5950406e4067
---
M sites/all/modules/wmf_civicrm/wmf_civicrm.module
M sites/all/modules/wmf_common/WmfException.php
2 files changed, 20 insertions(+), 8 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm
refs/changes/57/319757/1
diff --git a/sites/all/modules/wmf_civicrm/wmf_civicrm.module
b/sites/all/modules/wmf_civicrm/wmf_civicrm.module
index 06913be..636229b 100644
--- a/sites/all/modules/wmf_civicrm/wmf_civicrm.module
+++ b/sites/all/modules/wmf_civicrm/wmf_civicrm.module
@@ -450,7 +450,8 @@
throw new WmfException(
'INVALID_MESSAGE',
'Cannot create contribution, civi error!',
- $e->getMessage() . print_r($e->getExtraParams(), TRUE)
+ $e->getMessage(),
+ $e->getExtraParams()
);
}
diff --git a/sites/all/modules/wmf_common/WmfException.php
b/sites/all/modules/wmf_common/WmfException.php
index cd5d3b8..1fed299 100644
--- a/sites/all/modules/wmf_common/WmfException.php
+++ b/sites/all/modules/wmf_common/WmfException.php
@@ -107,36 +107,47 @@
var $extra;
var $type;
+ var $userMessage;
- function __construct( $type, $message, $extra = null ) {
+ function __construct( $type, $message, $apiMessage = '', $extra = array())
{
if ( !array_key_exists( $type, self::$error_types ) ) {
$message .= ' -- ' . t( 'Warning, throwing a misspelled exception:
"%type"', array( '%type' => $type ) );
$type = 'UNKNOWN';
}
$this->type = $type;
$this->code = constant( 'WmfException::' . $type );
+ if (empty($extra) && $apiMessage) {
+ $extra['error_message'] = var_export( $apiMessage, TRUE );
+ }
$this->extra = $extra;
if ( is_array( $message ) ) {
$message = implode( "\n", $message );
}
$this->message = "{$this->type} {$message}";
-
- if ( $extra ) {
- $this->message .= "\nSource: " . var_export( $extra, true );
- }
+ $this->userMessage = $this->message;
+ $this->message = $this->message . "\nSource: " . var_export(
$this->extra, true );
if ( function_exists( 'watchdog' ) ) {
// It seems that dblog_watchdog will pass through XSS, so
// rely on our own escaping above, rather than pass $vars.
- $escaped = htmlspecialchars( $this->message, ENT_COMPAT, 'UTF-8',
false );
+ $escaped = htmlspecialchars( $this->getMessage(), ENT_COMPAT,
'UTF-8', false );
watchdog( 'wmf_common', $escaped, NULL, WATCHDOG_ERROR );
}
if ( function_exists('drush_set_error') && $this->isFatal() ) {
- drush_set_error( $this->type, $this->message );
+ drush_set_error( $this->type, $this->getMessage() );
}
}
+ /**
+ * Get error message intended for end users.
+ *
+ * @return string
+ */
+ function getUserErrorMessage() {
+ return !empty($this->extra['error_message']) ?
$this->extra['error_message'] : $this->userMessage;
+ }
+
function getErrorName()
{
return $this->type;
--
To view, visit https://gerrit.wikimedia.org/r/319757
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Icd69c23dd4387aff720cdc9d6b0e5950406e4067
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: master
Gerrit-Owner: Eileen <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits