mirror of
https://github.com/flarum/core.git
synced 2025-08-01 22:20:21 +02:00
Improve API error handling
- Change 'path' key to 'source.pointer', as per spec - Add 500 error detail if debug mode is on
This commit is contained in:
@@ -12,6 +12,21 @@ namespace Flarum\Core\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class InvalidConfirmationTokenException extends Exception
|
||||
class InvalidConfirmationTokenException extends Exception implements JsonApiSerializable
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getStatusCode()
|
||||
{
|
||||
return 403;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getErrors()
|
||||
{
|
||||
return ['code' => 'invalid_confirmation_token'];
|
||||
}
|
||||
}
|
||||
|
@@ -27,9 +27,7 @@ class ValidationException extends Exception implements JsonApiSerializable
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the HTTP status code to be used for this exception.
|
||||
*
|
||||
* @return int
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getStatusCode()
|
||||
{
|
||||
@@ -37,15 +35,14 @@ class ValidationException extends Exception implements JsonApiSerializable
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of errors, formatted as JSON-API error objects.
|
||||
*
|
||||
* @see http://jsonapi.org/format/#error-objects
|
||||
* @return array
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getErrors()
|
||||
{
|
||||
return array_map(function ($path, $detail) {
|
||||
return compact('path', 'detail');
|
||||
$source = ['pointer' => '/data/attributes/' . $path];
|
||||
|
||||
return compact('source', 'detail');
|
||||
}, array_keys($this->messages), $this->messages);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user