1
0
mirror of https://github.com/flarum/core.git synced 2025-07-29 20:50:28 +02:00
Files
php-flarum/src/Core/Exceptions/ValidationException.php
Toby Zerner 8cccaaaf6b Improve API error handling
- Change 'path' key to 'source.pointer', as per spec
- Add 500 error detail if debug mode is on
2015-09-14 15:40:07 +09:30

49 lines
969 B
PHP

<?php
/*
* This file is part of Flarum.
*
* (c) Toby Zerner <toby.zerner@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Flarum\Core\Exceptions;
use Exception;
class ValidationException extends Exception implements JsonApiSerializable
{
protected $messages;
public function __construct(array $messages)
{
$this->messages = $messages;
}
public function getMessages()
{
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);
}
}