Skip to content

Commit

Permalink
Implement HTTP response codes for exceptions
Browse files Browse the repository at this point in the history
Exceptions should return HTTP response codes indicating an error, rather
than a successful request. 4xx errors can be used for errors with data
that the user has submitted. 5xx errors for unexpected server errors.

The error page generator still needs to implement response codes.
  • Loading branch information
davidhicks committed Jul 17, 2011
1 parent 354ce79 commit a0072fd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
1 change: 1 addition & 0 deletions application/MantisBT/Exception/Access/AccessDenied.php
Expand Up @@ -8,5 +8,6 @@ class AccessDenied extends ExceptionAbstract {
public function __construct() {
$errorMessage = lang_get(ERROR_ACCESS_DENIED, null, false);
parent::__construct( ERROR_ACCESS_DENIED, $errorMessage, null );
$this->responseCode = 403;
}
}
27 changes: 13 additions & 14 deletions application/MantisBT/Exception/ExceptionAbstract.php
Expand Up @@ -3,25 +3,24 @@
use \Exception;

abstract class ExceptionAbstract extends Exception {
protected $message = 'Unknown exception'; // Exception message
private $string; // Unknown
protected $code = 0; // User-defined exception code
protected $file; // Source filename of exception
protected $line; // Source line of exception
private $trace; // Unknown
protected $code = 0;
protected $message = 'Unknown exception';
protected $file;
protected $line;
protected $responseCode = 500;
private $trace;
private $context = null;

private $context = null; // Mantis Context
public function __construct($code = 0, $parameters = null, Exception $previous = null) {
public function __construct($code = 0, $parameters = null, Exception $previous = null) {
$message = var_export( $parameters, true);

$this->context = $parameters;
parent::__construct($message, $code, $previous);
}
parent::__construct($message, $code, $previous);
}

public function __toString() {
return get_class( $this ) . " '{$this->message}' in {$this->file}({$this->line})\n"
. "{$this->getTraceAsString()}";
}
public function __toString() {
return get_class( $this ) . " '{$this->message}' in {$this->file}({$this->line})\n" . "{$this->getTraceAsString()}";
}

public function getContext() {
return $this->context;
Expand Down
1 change: 1 addition & 0 deletions application/MantisBT/Exception/Field/EmptyField.php
Expand Up @@ -9,5 +9,6 @@ public function __construct($fieldName) {
$errorMessage = lang_get(ERROR_EMPTY_FIELD, null, false);
$errorMessage = sprintf($errorMessage, $fieldName);
parent::__construct(ERROR_EMPTY_FIELD, $errorMessage, null);
$this->responseCode = 400;
}
}

0 comments on commit a0072fd

Please sign in to comment.