From 2c231aa4757b2281f0f8448d983a07176650e238 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Fri, 9 Aug 2019 20:42:03 +0200 Subject: [PATCH] Make existing extensions compatible with new stack --- src/Api/Exception/InvalidAccessTokenException.php | 7 ++++++- src/Http/Exception/ForbiddenException.php | 7 ++++--- src/Http/Exception/MethodNotAllowedException.php | 7 ++++--- src/Http/Exception/RouteNotFoundException.php | 7 ++++--- src/Http/Exception/TokenMismatchException.php | 7 ++++--- src/Post/Exception/FloodingException.php | 7 ++++++- src/User/Exception/InvalidConfirmationTokenException.php | 7 ++++++- src/User/Exception/PermissionDeniedException.php | 7 ++++--- 8 files changed, 38 insertions(+), 18 deletions(-) diff --git a/src/Api/Exception/InvalidAccessTokenException.php b/src/Api/Exception/InvalidAccessTokenException.php index ec8824636..94ac90952 100644 --- a/src/Api/Exception/InvalidAccessTokenException.php +++ b/src/Api/Exception/InvalidAccessTokenException.php @@ -10,7 +10,12 @@ namespace Flarum\Api\Exception; use Exception; +use Flarum\Foundation\KnownError; -class InvalidAccessTokenException extends Exception +class InvalidAccessTokenException extends Exception implements KnownError { + public function getType(): string + { + return 'invalid_access_token'; + } } diff --git a/src/Http/Exception/ForbiddenException.php b/src/Http/Exception/ForbiddenException.php index e178249f6..88c6555f0 100644 --- a/src/Http/Exception/ForbiddenException.php +++ b/src/Http/Exception/ForbiddenException.php @@ -10,11 +10,12 @@ namespace Flarum\Http\Exception; use Exception; +use Flarum\Foundation\KnownError; -class ForbiddenException extends Exception +class ForbiddenException extends Exception implements KnownError { - public function __construct($message = null, $code = 403, Exception $previous = null) + public function getType(): string { - parent::__construct($message, $code, $previous); + return 'forbidden'; } } diff --git a/src/Http/Exception/MethodNotAllowedException.php b/src/Http/Exception/MethodNotAllowedException.php index d22fa3865..a416c0d0f 100644 --- a/src/Http/Exception/MethodNotAllowedException.php +++ b/src/Http/Exception/MethodNotAllowedException.php @@ -10,11 +10,12 @@ namespace Flarum\Http\Exception; use Exception; +use Flarum\Foundation\KnownError; -class MethodNotAllowedException extends Exception +class MethodNotAllowedException extends Exception implements KnownError { - public function __construct($message = null, $code = 405, Exception $previous = null) + public function getType(): string { - parent::__construct($message, $code, $previous); + return 'method_not_allowed'; } } diff --git a/src/Http/Exception/RouteNotFoundException.php b/src/Http/Exception/RouteNotFoundException.php index 771c2cc24..ca41fc92a 100644 --- a/src/Http/Exception/RouteNotFoundException.php +++ b/src/Http/Exception/RouteNotFoundException.php @@ -10,11 +10,12 @@ namespace Flarum\Http\Exception; use Exception; +use Flarum\Foundation\KnownError; -class RouteNotFoundException extends Exception +class RouteNotFoundException extends Exception implements KnownError { - public function __construct($message = null, $code = 404, Exception $previous = null) + public function getType(): string { - parent::__construct($message, $code, $previous); + return 'route_not_found'; } } diff --git a/src/Http/Exception/TokenMismatchException.php b/src/Http/Exception/TokenMismatchException.php index fc3225f47..a0c20c0f8 100644 --- a/src/Http/Exception/TokenMismatchException.php +++ b/src/Http/Exception/TokenMismatchException.php @@ -10,11 +10,12 @@ namespace Flarum\Http\Exception; use Exception; +use Flarum\Foundation\KnownError; -class TokenMismatchException extends Exception +class TokenMismatchException extends Exception implements KnownError { - public function __construct($message = null, $code = 419, Exception $previous = null) + public function getType(): string { - parent::__construct($message, $code, $previous); + return 'csrf_token_mismatch'; } } diff --git a/src/Post/Exception/FloodingException.php b/src/Post/Exception/FloodingException.php index 6cf786026..8c5b39d89 100644 --- a/src/Post/Exception/FloodingException.php +++ b/src/Post/Exception/FloodingException.php @@ -10,7 +10,12 @@ namespace Flarum\Post\Exception; use Exception; +use Flarum\Foundation\KnownError; -class FloodingException extends Exception +class FloodingException extends Exception implements KnownError { + public function getType(): string + { + return 'too_many_requests'; + } } diff --git a/src/User/Exception/InvalidConfirmationTokenException.php b/src/User/Exception/InvalidConfirmationTokenException.php index 0eb89b57e..e06e7ef2e 100644 --- a/src/User/Exception/InvalidConfirmationTokenException.php +++ b/src/User/Exception/InvalidConfirmationTokenException.php @@ -10,7 +10,12 @@ namespace Flarum\User\Exception; use Exception; +use Flarum\Foundation\KnownError; -class InvalidConfirmationTokenException extends Exception +class InvalidConfirmationTokenException extends Exception implements KnownError { + public function getType(): string + { + return 'invalid_confirmation_token'; + } } diff --git a/src/User/Exception/PermissionDeniedException.php b/src/User/Exception/PermissionDeniedException.php index 22097af8f..cebe8db80 100644 --- a/src/User/Exception/PermissionDeniedException.php +++ b/src/User/Exception/PermissionDeniedException.php @@ -10,11 +10,12 @@ namespace Flarum\User\Exception; use Exception; +use Flarum\Foundation\KnownError; -class PermissionDeniedException extends Exception +class PermissionDeniedException extends Exception implements KnownError { - public function __construct($message = null, $code = 403, Exception $previous = null) + public function getType(): string { - parent::__construct($message, $code, $previous); + return 'permission_denied'; } }