From 5b5ef2fed7ee584faeec533ed9892b6e8c6fdc77 Mon Sep 17 00:00:00 2001 From: xamgore <xamgore@ya.ru> Date: Sat, 11 Jun 2016 13:41:58 +0300 Subject: [PATCH] Return err message with 422 exception --- ~dev_rating/application/classes/Controller/Handler.php | 4 ++-- ~dev_rating/system/classes/Kohana/HTTP/Exception/Expected.php | 3 +++ ~dev_rating/system/classes/Kohana/Response.php | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/~dev_rating/application/classes/Controller/Handler.php b/~dev_rating/application/classes/Controller/Handler.php index 75f4b38ae..62b501c03 100644 --- a/~dev_rating/application/classes/Controller/Handler.php +++ b/~dev_rating/application/classes/Controller/Handler.php @@ -26,7 +26,7 @@ class Controller_Handler extends Controller return $res; } - protected function fail() { - throw HTTP_Exception::factory(422)->request($this->request); + protected function fail($message = null) { + throw HTTP_Exception::factory(422, $message)->request($this->request); } } diff --git a/~dev_rating/system/classes/Kohana/HTTP/Exception/Expected.php b/~dev_rating/system/classes/Kohana/HTTP/Exception/Expected.php index 4d08def2f..920c83098 100644 --- a/~dev_rating/system/classes/Kohana/HTTP/Exception/Expected.php +++ b/~dev_rating/system/classes/Kohana/HTTP/Exception/Expected.php @@ -35,6 +35,9 @@ abstract class Kohana_HTTP_Exception_Expected extends HTTP_Exception { // Prepare our response object and set the correct status code. $this->_response = Response::factory() ->status($this->_code); + + if (!is_null($message)) + $this->_response->body($message); } /** diff --git a/~dev_rating/system/classes/Kohana/Response.php b/~dev_rating/system/classes/Kohana/Response.php index 67abf2d7a..111532bf4 100644 --- a/~dev_rating/system/classes/Kohana/Response.php +++ b/~dev_rating/system/classes/Kohana/Response.php @@ -196,7 +196,7 @@ class Kohana_Response implements HTTP_Response { * $status = $response->status(); * * @param integer $status Status to set to this response - * @return mixed + * @return self|mixed */ public function status($status = NULL) { -- GitLab