Repository navigation
Expand file tree
/
Copy pathResourceException.php
More file actions
69 lines (61 loc) · 1.52 KB
/
Copy pathResourceException.php
File metadata and controls
69 lines (61 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
namespace Dingo\Api\Exception;
use Exception;
use Illuminate\Support\MessageBag;
use Symfony\Component\HttpKernel\Exception\HttpException;
class ResourceException extends HttpException
{
/**
* MessageBag errors.
*
* @var \Illuminate\Support\MessageBag
*/
protected $errors;
/**
* Create a new resource exception instance.
*
* @param int $statusCode
* @param string $message
* @param \Illuminate\Support\MessageBag|array $errors
* @param \Exception $previous
* @param array $headers
* @param int $code
* @return void
*/
public function __construct($message = null, $errors = null, Exception $previous = null, $headers = [], $code = 0)
{
if (is_null($errors)) {
$this->errors = new MessageBag;
} else {
$this->errors = is_array($errors) ? new MessageBag($errors) : $errors;
}
parent::__construct(422, $message, $previous, $headers, $code);
}
/**
* Get the errors message bag.
*
* @return \Illuminate\Support\MessageBag
**/
public function errors()
{
return $this->getErrors();
}
/**
* Get the errors message bag.
*
* @return \Illuminate\Support\MessageBag
**/
public function getErrors()
{
return $this->errors;
}
/**
* Determine if message bag has any errors.
*
* @return bool
*/
public function hasErrors()
{
return ! $this->errors->isEmpty();
}
}