Skip to content
Snippets Groups Projects
Commit a6b8c184 authored by Olav Morken's avatar Olav Morken
Browse files

Utilities::fatalError: Add possibility for replacements in error text.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@792 44740490-163a-0410-bde0-09ae8108e29a
parent 105c385a
No related branches found
No related tags found
No related merge requests found
......@@ -388,22 +388,50 @@ class SimpleSAML_Utilities {
/**
* Show and log fatal error message.
*
* This function logs a error message to the error log and shows the
* message to the user. Script execution terminates afterwards.
*
* @param $title Short title for the error message.
* @param $message The error message.
* The error code comes from the errors-dictionary. It can optionally include parameters, which
* will be substituted into the output string.
*
* @param string $trackid The trackid of the user, from $session->getTrackID().
* @param mixed $errorcode Either a string with the error code, or an array with the error code and
* additional parameters.
* @param Exception $e The exception which caused the error.
*/
public static function fatalError($trackid = 'na', $errorcode = null, Exception $e = null, $level = LOG_ERR) {
public static function fatalError($trackid = 'na', $errorcode = null, Exception $e = null) {
$config = SimpleSAML_Configuration::getInstance();
if(is_array($errorcode)) {
$parameters = $errorcode;
unset($parameters[0]);
$errorcode = $errorcode[0];
} else {
$parameters = array();
}
// Get the exception message if there is any exception provided.
$emsg = (empty($e) ? 'No exception available' : $e->getMessage());
$etrace = (empty($e) ? 'No exception available' : $e->getTraceAsString());
if(!empty($errorcode) && count($parameters) > 0) {
$reptext = array();
foreach($parameters as $k => $v) {
$reptext[] = '"' . $k . '"' . ' => "' . $v . '"';
}
$reptext = '(' . implode(', ', $reptext) . ')';
$error = $errorcode . $reptext;
} elseif(!empty($errorcode)) {
$error = $errorcode;
} else {
$error = 'na';
}
// Log a error message
SimpleSAML_Logger::error($_SERVER['PHP_SELF'].' - UserError: ErrCode:'.(!empty($errorcode) ? $errorcode : 'na').': '.urlencode($emsg) );
SimpleSAML_Logger::error($_SERVER['PHP_SELF'].' - UserError: ErrCode:' . $error . ': ' . urlencode($emsg) );
$languagefile = null;
if (isset($errorcode)) $languagefile = 'errors';
......@@ -413,7 +441,8 @@ class SimpleSAML_Utilities {
$t->data['errorcode'] = $errorcode;
$t->data['parameters'] = $parameters;
$t->data['showerrors'] = $config->getValue('showerrors', true);
/* Check if there is a valid technical contact email address. */
......
......@@ -11,8 +11,9 @@
?></h2>
<?php
if($this->t('descr_' . $this->data['errorcode'])) {
echo $this->t('descr_' . $this->data['errorcode']);
$descr = $this->t('descr_' . $this->data['errorcode'], $this->data['parameters']);
if($descr) {
echo htmlspecialchars($descr);
}
?>
......@@ -67,6 +68,7 @@ if (!empty($this->data['errorreportaddress'])) {
<input type="hidden" name="exceptionmsg" value="<?php echo htmlspecialchars($this->data['exceptionmsg']); ?>" />
<input type="hidden" name="exceptiontrace" value="<?php echo htmlspecialchars($this->data['exceptiontrace']); ?>" />
<input type="hidden" name="errorcode" value="<?php echo htmlspecialchars($this->data['errorcode']); ?>" />
<input type="hidden" name="parameters" value="<?php echo htmlspecialchars(var_export($this->data['parameters'], TRUE)); ?>" />
<input type="hidden" name="url" value="<?php echo htmlspecialchars($this->data['url']); ?>" />
<input type="submit" name="send" value="<?php echo $this->t('report_submit'); ?>" />
......
......@@ -22,6 +22,7 @@ $mailFormat = array(
'email' => 'Email address of submitter',
'url' => 'URL of page where the error occured',
'errorcode' => 'Error code',
'parameters' => 'Parameters for the error',
'text' => 'Message from user',
'trackid' => 'Track id for the user\' session',
'exceptionmsg' => 'Exception message',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment