From 65ef71d97ac9ab5a107040958143d43e3212999c Mon Sep 17 00:00:00 2001 From: Olav Morken <olav.morken@uninett.no> Date: Tue, 12 Aug 2008 11:05:09 +0000 Subject: [PATCH] Added BadRequest error. git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@802 44740490-163a-0410-bde0-09ae8108e29a --- dictionaries/errors.php | 6 ++++ lib/SimpleSAML/Error/BadRequest.php | 56 +++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 lib/SimpleSAML/Error/BadRequest.php diff --git a/dictionaries/errors.php b/dictionaries/errors.php index aa468a98a..0d6763cc0 100644 --- a/dictionaries/errors.php +++ b/dictionaries/errors.php @@ -1020,6 +1020,12 @@ $lang = array( 'sl' => 'Strani ni bilo mogoče najti. Razlog: %REASON%. Naveden URL strani je bil: %URL%', 'hu' => '%URL% oldal nem található, a következő ok miatt: %REASON% ', ), + 'title_BADREQUEST' => array ( + 'en' => 'Bad request received', + ), + 'descr_BADREQUEST' => array ( + 'en' => 'There is an error in the request to this page. The reason was: %REASON%', + ), ); diff --git a/lib/SimpleSAML/Error/BadRequest.php b/lib/SimpleSAML/Error/BadRequest.php new file mode 100644 index 000000000..f7dabdb54 --- /dev/null +++ b/lib/SimpleSAML/Error/BadRequest.php @@ -0,0 +1,56 @@ +<?php + +/** + * Exception which will show a 400 Bad Request error page. + * + * This exception can be thrown from within an module page handler. The user will then be + * shown a 400 Bad Request error page. + * + * @author Olav Morken, UNINETT AS. + * @package simpleSAMLphp + * @version $Id$ + */ +class SimpleSAML_Error_BadRequest extends SimpleSAML_Error_Error { + + + /** + * Reason why this request was invalid. + */ + private $reason; + + + /** + * Create a new BadRequest error. + * + * @param string $reason Description of why the request was unacceptable. + */ + public function __construct($reason) { + assert('is_string($reason)'); + + $this->reason = $reason; + parent::__construct(array('BADREQUEST', '%REASON%' => $this->reason)); + } + + + /** + * Retrieve the reason why the request was invalid. + * + * @return string The reason why the request was invalid. + */ + public function getReason() { + return $this->reason; + } + + + /** + * Set the HTTP return code for this error. + * + * This should be overridden by subclasses who want a different return code than 500 Internal Server Error. + */ + protected function setHTTPCode() { + header('HTTP/1.0 400 Bad Request'); + } + +} + +?> \ No newline at end of file -- GitLab