From bba35875a3987846b039a4b718a118807af01e72 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Tue, 20 May 2014 20:51:07 +0200 Subject: [PATCH] Added HTTP status codes to exception interceptors --- src/Controllers/ApiController.php | 1 + src/Controllers/AuthController.php | 1 + src/Controllers/PostController.php | 1 + src/Controllers/TagController.php | 2 ++ src/Controllers/UserController.php | 42 +++++++++++++++++------------- 5 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/Controllers/ApiController.php b/src/Controllers/ApiController.php index 5a8d5c43..09cc1caf 100644 --- a/src/Controllers/ApiController.php +++ b/src/Controllers/ApiController.php @@ -39,6 +39,7 @@ class ApiController extends AbstractController } catch (Exception $e) { + \Chibi\Util\Headers::setCode(400); Messenger::fail($e->getMessage()); } diff --git a/src/Controllers/AuthController.php b/src/Controllers/AuthController.php index 9f215d12..de18e38d 100644 --- a/src/Controllers/AuthController.php +++ b/src/Controllers/AuthController.php @@ -20,6 +20,7 @@ class AuthController extends AbstractController } catch (SimpleException $e) { + \Chibi\Util\Headers::setCode(400); Messenger::fail($e->getMessage()); $this->renderView('auth-login'); } diff --git a/src/Controllers/PostController.php b/src/Controllers/PostController.php index 6537d503..00d9b816 100644 --- a/src/Controllers/PostController.php +++ b/src/Controllers/PostController.php @@ -34,6 +34,7 @@ class PostController extends AbstractController } catch (SimpleException $e) { + \Chibi\Util\Headers::setCode(400); Messenger::fail($e->getMessage()); } diff --git a/src/Controllers/TagController.php b/src/Controllers/TagController.php index 4c819bf0..99baa4ce 100644 --- a/src/Controllers/TagController.php +++ b/src/Controllers/TagController.php @@ -93,6 +93,7 @@ class TagController extends AbstractController } catch (SimpleException $e) { + \Chibi\Util\Headers::setCode(400); Messenger::fail($e->getMessage()); } @@ -119,6 +120,7 @@ class TagController extends AbstractController } catch (Exception $e) { + \Chibi\Util\Headers::setCode(400); Messenger::fail($e->getMessage()); } diff --git a/src/Controllers/UserController.php b/src/Controllers/UserController.php index 3048af40..428205d9 100644 --- a/src/Controllers/UserController.php +++ b/src/Controllers/UserController.php @@ -53,6 +53,7 @@ class UserController extends AbstractController } catch (SimpleException $e) { + \Chibi\Util\Headers::setCode(400); Messenger::fail($e->getMessage()); } @@ -106,6 +107,7 @@ class UserController extends AbstractController } catch (SimpleException $e) { + \Chibi\Util\Headers::setCode(400); Messenger::fail($e->getMessage()); } @@ -132,6 +134,7 @@ class UserController extends AbstractController } catch (SimpleException $e) { + \Chibi\Util\Headers::setCode(400); Messenger::fail($e->getMessage()); $this->renderView('user-view'); } @@ -233,6 +236,7 @@ class UserController extends AbstractController } catch (SimpleException $e) { + \Chibi\Util\Headers::setCode(400); Messenger::fail($e->getMessage()); } @@ -252,30 +256,31 @@ class UserController extends AbstractController try { - if (empty($tokenText)) - { - Api::run( - new ActivateUserEmailJob(), - $this->appendUserIdentifierArgument([], $identifier)); + if (empty($tokenText)) + { + Api::run( + new ActivateUserEmailJob(), + $this->appendUserIdentifierArgument([], $identifier)); - Messenger::success('Activation e-mail resent.'); - } - else - { - $user = Api::run(new ActivateUserEmailJob(), [ - JobArgs::ARG_TOKEN => $tokenText ]); + Messenger::success('Activation e-mail resent.'); + } + else + { + $user = Api::run(new ActivateUserEmailJob(), [ + JobArgs::ARG_TOKEN => $tokenText ]); - $message = 'Activation completed successfully.'; - if (Core::getConfig()->registration->staffActivation) - $message .= ' However, your account still must be confirmed by staff.'; - Messenger::success($message); + $message = 'Activation completed successfully.'; + if (Core::getConfig()->registration->staffActivation) + $message .= ' However, your account still must be confirmed by staff.'; + Messenger::success($message); - if (!Core::getConfig()->registration->staffActivation) - Auth::setCurrentUser($user); - } + if (!Core::getConfig()->registration->staffActivation) + Auth::setCurrentUser($user); + } } catch (SimpleException $e) { + \Chibi\Util\Headers::setCode(400); Messenger::fail($e->getMessage()); } @@ -316,6 +321,7 @@ class UserController extends AbstractController } catch (SimpleException $e) { + \Chibi\Util\Headers::setCode(400); Messenger::fail($e->getMessage()); }