Skip to content
Snippets Groups Projects
Commit 84a6debe authored by Роман Штейнберг's avatar Роман Штейнберг Committed by Artem Konenko
Browse files

ADD: http api exceptions implementation

parent 48b83ab3
Branches
Tags
No related merge requests found
<?php defined('SYSPATH') or die('No direct script access.');
class HTTP_API_Exception extends HTTP_Exception
{
/**
* Creates an HTTP_Exception of the specified type.
*
* @param integer $code the http status code
* @param string $message status message, custom content to display with error
* @param array $variables translation variables
* @return HTTP_Exception
*/
public static function factory($code, $message = NULL, array $variables = NULL, Exception $previous = NULL) {
$class = 'HTTP_API_Exception_' . $code;
return new $class($message, $variables, $previous);
}
public function get_response() {
// Lets log the Exception, Just in case it's important!
Kohana_Exception::log($this);
$twig = Twig::factory('errors/http_api');
$twig->code = $this->getCode();
$twig->message = $this->getMessage();
$twig->link = URL::site('');
$response = Response::factory()
->status($this->getCode())
->body($twig);
return $response;
}
}
\ No newline at end of file
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
<div class="logotype alignLeft"> <div class="logotype alignLeft">
{{ HTML.anchor('/', System.Title, {'title': 'Перейти на главную'})|raw }} {{ HTML.anchor('/', System.Title, {'title': 'Перейти на главную'})|raw }}
</div> </div>
<div class="faculty alignLeft">{{ User.FacultyName }}</div>
<div class="navigation"> <div class="navigation">
Ooops! Ooops!
</div> </div>
......
{
"code": "{{ code }}",
"message": "{{ message }}"
}
\ No newline at end of file
<?php defined('SYSPATH') OR die('No direct script access.');
class HTTP_API_Exception_400 extends HTTP_API_Exception {
protected $_code = 400;
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment