Skip to content
Snippets Groups Projects
Commit 8eefc243 authored by xamgore's avatar xamgore
Browse files

Create new server-logic based error

parent 02a18513
Branches
Tags
No related merge requests found
......@@ -16,4 +16,17 @@ class Controller_Handler extends Controller
$this->post = Validation::factory(Arr::map('trim', $_POST));
$this->get = Validation::factory(Arr::map('trim', $_GET));
}
public function execute() {
$res = parent::execute();
if (empty($res->body()))
$res->body(json_encode([]));
return $res;
}
protected function fail() {
throw HTTP_Exception::factory(422)->request($this->request);
}
}
<?php defined('SYSPATH') OR die('No direct script access.');
class HTTP_Exception_422 extends Kohana_HTTP_Exception_422 {}
<?php defined('SYSPATH') OR die('No direct script access.');
class Kohana_HTTP_Exception_422 extends HTTP_Exception_Expected
{
/** @var int Unprocessable Entity */
protected $_code = 422;
/**
* Specifies the list of allowed HTTP methods
*
* @param array $methods List of allowed methods
* @return $this
*/
public function allowed($methods) {
if (is_array($methods)) {
$methods = implode(',', $methods);
}
$this->headers('allow', $methods);
return $this;
}
/**
* Validate this exception contains everything needed to continue.
*
* @throws Kohana_Exception
* @return bool
*/
public function check() {
// if ($location = $this->headers('allow') === null)
// throw new Kohana_Exception('A list of allowed methods must be specified');
return true;
}
}
......@@ -75,6 +75,7 @@ class Kohana_Response implements HTTP_Response {
415 => 'Unsupported Media Type',
416 => 'Requested Range Not Satisfiable',
417 => 'Expectation Failed',
422 => 'Unprocessable Entity',
// Server Error 5xx
500 => 'Internal Server Error',
......
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