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

SimpleSAML_Error: Support for custom error codes.

Thanks to Andjelko Horvat for implementing this.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2724 44740490-163a-0410-bde0-09ae8108e29a
parent 4a40275e
No related branches found
No related tags found
No related merge requests found
...@@ -18,6 +18,30 @@ class SimpleSAML_Error_Error extends SimpleSAML_Error_Exception { ...@@ -18,6 +18,30 @@ class SimpleSAML_Error_Error extends SimpleSAML_Error_Exception {
private $errorCode; private $errorCode;
/**
* The error title tag in dictionary.
*
* @var string
*/
private $dictTitle;
/**
* The error description tag in dictionary.
*
* @var string
*/
private $dictDescr;
/**
* The name of module which throw error.
*
* @var string|NULL
*/
private $module = NULL;
/** /**
* The parameters for the error. * The parameters for the error.
* *
...@@ -48,6 +72,16 @@ class SimpleSAML_Error_Error extends SimpleSAML_Error_Exception { ...@@ -48,6 +72,16 @@ class SimpleSAML_Error_Error extends SimpleSAML_Error_Exception {
$this->errorCode = $errorCode; $this->errorCode = $errorCode;
} }
$moduleCode = explode(':', $this->errorCode, 2);
if (count($moduleCode) === 2) {
$this->module = $moduleCode[0];
$this->dictTitle = '{' . $this->module . ':errors:title_' . $moduleCode[1] . '}';
$this->dictDescr = '{' . $this->module . ':errors:descr_' . $moduleCode[1] . '}';
} else {
$this->dictTitle = '{errors:title_' . $this->errorCode . '}';
$this->dictDescr = '{errors:descr_' . $this->errorCode . '}';
}
if (!empty($this->parameters)) { if (!empty($this->parameters)) {
$msg = $this->errorCode . '('; $msg = $this->errorCode . '(';
foreach ($this->parameters as $k => $v) { foreach ($this->parameters as $k => $v) {
...@@ -75,6 +109,36 @@ class SimpleSAML_Error_Error extends SimpleSAML_Error_Exception { ...@@ -75,6 +109,36 @@ class SimpleSAML_Error_Error extends SimpleSAML_Error_Exception {
} }
/**
* Retrieve the error parameters given when throwing this error.
*
* @return array The parameters.
*/
public function getParameters() {
return $this->parameters;
}
/**
* Retrieve the error title tag in dictionary.
*
* @return string The error title tag.
*/
public function getDictTitle() {
return $this->dictTitle;
}
/**
* Retrieve the error description tag in dictionary.
*
* @return string The error description tag.
*/
public function getDictDescr() {
return $this->dictDescr;
}
/** /**
* Set the HTTP return code for this error. * Set the HTTP return code for this error.
* *
...@@ -150,6 +214,9 @@ class SimpleSAML_Error_Error extends SimpleSAML_Error_Exception { ...@@ -150,6 +214,9 @@ class SimpleSAML_Error_Error extends SimpleSAML_Error_Exception {
$data['error'] = $errorData; $data['error'] = $errorData;
$data['errorCode'] = $this->errorCode; $data['errorCode'] = $this->errorCode;
$data['parameters'] = $this->parameters; $data['parameters'] = $this->parameters;
$data['module'] = $this->module;
$data['dictTitle'] = $this->dictTitle;
$data['dictDescr'] = $this->dictDescr;
/* Check if there is a valid technical contact email address. */ /* Check if there is a valid technical contact email address. */
if($config->getString('technicalcontact_email', 'na@example.org') !== 'na@example.org') { if($config->getString('technicalcontact_email', 'na@example.org') !== 'na@example.org') {
......
...@@ -9,10 +9,10 @@ ...@@ -9,10 +9,10 @@
?> ?>
<h2><?php echo $this->t('title_' . $this->data['errorCode']); ?></h2> <h2><?php echo $this->t($this->data['dictTitle']); ?></h2>
<?php <?php
echo htmlspecialchars($this->t('descr_' . $this->data['errorCode'], $this->data['parameters'])); echo htmlspecialchars($this->t($this->data['dictDescr'], $this->data['parameters']));
?> ?>
<div class="trackidtext"> <div class="trackidtext">
......
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