mirror of
https://github.com/flarum/core.git
synced 2025-08-04 15:37:51 +02:00
Use exception handlers instead of JsonApiSerializableInterface
This commit is contained in:
@@ -11,23 +11,7 @@
|
||||
namespace Flarum\Core\Exception;
|
||||
|
||||
use Exception;
|
||||
use Tobscure\JsonApi\Exception\JsonApiSerializableInterface;
|
||||
|
||||
class FloodingException extends Exception implements JsonApiSerializableInterface
|
||||
class FloodingException extends Exception
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getStatusCode()
|
||||
{
|
||||
return 429;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getErrors()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
@@ -11,23 +11,7 @@
|
||||
namespace Flarum\Core\Exception;
|
||||
|
||||
use Exception;
|
||||
use Tobscure\JsonApi\Exception\JsonApiSerializableInterface;
|
||||
|
||||
class InvalidConfirmationTokenException extends Exception implements JsonApiSerializableInterface
|
||||
class InvalidConfirmationTokenException extends Exception
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getStatusCode()
|
||||
{
|
||||
return 403;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getErrors()
|
||||
{
|
||||
return ['code' => 'invalid_confirmation_token'];
|
||||
}
|
||||
}
|
||||
|
@@ -11,28 +11,7 @@
|
||||
namespace Flarum\Core\Exception;
|
||||
|
||||
use Exception;
|
||||
use Tobscure\JsonApi\Exception\JsonApiSerializableInterface;
|
||||
|
||||
class PermissionDeniedException extends Exception implements JsonApiSerializableInterface
|
||||
class PermissionDeniedException extends Exception
|
||||
{
|
||||
/**
|
||||
* Return the HTTP status code to be used for this exception.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getStatusCode()
|
||||
{
|
||||
return 401;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of errors, formatted as JSON-API error objects.
|
||||
*
|
||||
* @see http://jsonapi.org/format/#error-objects
|
||||
* @return array
|
||||
*/
|
||||
public function getErrors()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
@@ -11,9 +11,8 @@
|
||||
namespace Flarum\Core\Exception;
|
||||
|
||||
use Exception;
|
||||
use Tobscure\JsonApi\Exception\JsonApiSerializableInterface;
|
||||
|
||||
class ValidationException extends Exception implements JsonApiSerializableInterface
|
||||
class ValidationException extends Exception
|
||||
{
|
||||
protected $messages;
|
||||
|
||||
@@ -28,24 +27,4 @@ class ValidationException extends Exception implements JsonApiSerializableInterf
|
||||
{
|
||||
return $this->messages;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getStatusCode()
|
||||
{
|
||||
return 422;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getErrors()
|
||||
{
|
||||
return array_map(function ($path, $detail) {
|
||||
$source = ['pointer' => '/data/attributes/' . $path];
|
||||
|
||||
return compact('source', 'detail');
|
||||
}, array_keys($this->messages), $this->messages);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user