From e380b76e16a9fdc62b03740e5abeb7d1309dcd3e Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Sat, 30 Oct 2010 23:13:54 -0200 Subject: [PATCH] Created an exception to error 405 (Method Not Allowed) and changed the delete action in bake to use it. --- .../default/actions/controller_actions.ctp | 2 +- cake/libs/exceptions.php | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/cake/console/templates/default/actions/controller_actions.ctp b/cake/console/templates/default/actions/controller_actions.ctp index 137628c54..21e0827fc 100644 --- a/cake/console/templates/default/actions/controller_actions.ctp +++ b/cake/console/templates/default/actions/controller_actions.ctp @@ -116,7 +116,7 @@ public function delete($id = null) { if (!$this->request->is('post')) { - throw new ForbiddenException(); + throw new MethodNotAllowedException(); } if (!$id) { diff --git a/cake/libs/exceptions.php b/cake/libs/exceptions.php index daa1e7f39..fc153a0fe 100644 --- a/cake/libs/exceptions.php +++ b/cake/libs/exceptions.php @@ -99,6 +99,26 @@ class NotFoundException extends RuntimeException { } } +/** + * Represents an HTTP 405 error. + * + * @package cake.libs + */ +class MethodNotAllowedException extends RuntimeException { +/** + * Constructor + * + * @param string $message If no message is given 'Method Not Allowed' will be the message + * @param string $code Status code, defaults to 401 + */ + public function __construct($message = null, $code = 405) { + if (empty($message)) { + $message = 'Method Not Allowed'; + } + parent::__construct($message, $code); + } +} + /** * Represents an HTTP 500 error. *