diff --git a/~dev_rating/application/classes/HTTP/API/Exception.php b/~dev_rating/application/classes/HTTP/API/Exception.php new file mode 100644 index 0000000000000000000000000000000000000000..48f8231e500b797b757a571e090d4684b5e26209 --- /dev/null +++ b/~dev_rating/application/classes/HTTP/API/Exception.php @@ -0,0 +1,33 @@ +<?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 diff --git a/~dev_rating/application/views/errors/http.twig b/~dev_rating/application/views/errors/http.twig index 0fce6ba4909cc74579e5bf9cf5717d77d5688d86..66f2ffd1e82c1710c74ffaebf056d58d141b1a76 100644 --- a/~dev_rating/application/views/errors/http.twig +++ b/~dev_rating/application/views/errors/http.twig @@ -18,7 +18,6 @@ <div class="logotype alignLeft"> {{ HTML.anchor('/', System.Title, {'title': 'Перейти на главную'})|raw }} </div> - <div class="faculty alignLeft">{{ User.FacultyName }}</div> <div class="navigation"> Ooops! </div> diff --git a/~dev_rating/application/views/errors/http_api.twig b/~dev_rating/application/views/errors/http_api.twig new file mode 100644 index 0000000000000000000000000000000000000000..b88069e70e5017e8d05a0419593db4121a5b5e48 --- /dev/null +++ b/~dev_rating/application/views/errors/http_api.twig @@ -0,0 +1,4 @@ +{ + "code": "{{ code }}", + "message": "{{ message }}" +} \ No newline at end of file diff --git a/~dev_rating/system/classes/HTTP/API/Exception/400.php b/~dev_rating/system/classes/HTTP/API/Exception/400.php new file mode 100644 index 0000000000000000000000000000000000000000..23c73e85e5965bb60c8868a8f7b1b164aa387712 --- /dev/null +++ b/~dev_rating/system/classes/HTTP/API/Exception/400.php @@ -0,0 +1,5 @@ +<?php defined('SYSPATH') OR die('No direct script access.'); + +class HTTP_API_Exception_400 extends HTTP_API_Exception { + protected $_code = 400; +}