|
18 | 18 |
|
19 | 19 | namespace CloudCreativity\JsonApi\Http\Controllers;
|
20 | 20 |
|
21 |
| -use CloudCreativity\JsonApi\Error\ThrowableError; |
| 21 | +use CloudCreativity\JsonApi\Contracts\Error\ErrorObjectInterface; |
| 22 | +use CloudCreativity\JsonApi\Error\ErrorException; |
22 | 23 | use Illuminate\Http\Response;
|
23 | 24 | use Illuminate\Routing\Controller;
|
24 | 25 |
|
@@ -57,32 +58,60 @@ public function callAction($method, $parameters)
|
57 | 58 | /**
|
58 | 59 | * @param array $parameters
|
59 | 60 | * @return void
|
60 |
| - * @throws ThrowableError |
| 61 | + * @throws ErrorException |
61 | 62 | */
|
62 | 63 | public function missingMethod($parameters = [])
|
63 | 64 | {
|
64 |
| - throw new ThrowableError('Method Not Allowed', Response::HTTP_METHOD_NOT_ALLOWED); |
| 65 | + $this->methodNotAllowed(); |
65 | 66 | }
|
66 | 67 |
|
67 | 68 | /**
|
68 | 69 | * @param string $method
|
69 | 70 | * @param array $parameters
|
70 | 71 | * @return void
|
71 |
| - * @throws ThrowableError |
| 72 | + * @throws ErrorException |
72 | 73 | */
|
73 | 74 | public function __call($method, $parameters)
|
74 | 75 | {
|
75 |
| - throw new ThrowableError('Not Implemented', Response::HTTP_NOT_IMPLEMENTED); |
| 76 | + $this->notImplemented(); |
76 | 77 | }
|
77 | 78 |
|
78 | 79 | /**
|
79 | 80 | * Helper method to throw a not found exception.
|
80 | 81 | *
|
81 |
| - * @return void |
82 |
| - * @throws ThrowableError |
| 82 | + * @throws ErrorException |
83 | 83 | */
|
84 | 84 | public function notFound()
|
85 | 85 | {
|
86 |
| - throw new ThrowableError('Not Found', Response::HTTP_NOT_FOUND); |
| 86 | + throw new ErrorException([ |
| 87 | + ErrorObjectInterface::TITLE => 'Not Found', |
| 88 | + ErrorObjectInterface::STATUS => Response::HTTP_NOT_FOUND, |
| 89 | + ]); |
| 90 | + } |
| 91 | + |
| 92 | + /** |
| 93 | + * Helper method to throw a not implemented exception. |
| 94 | + * |
| 95 | + * @throws ErrorException |
| 96 | + */ |
| 97 | + public function notImplemented() |
| 98 | + { |
| 99 | + throw new ErrorException([ |
| 100 | + ErrorObjectInterface::TITLE => 'Not Implemented', |
| 101 | + ErrorObjectInterface::STATUS => Response::HTTP_NOT_IMPLEMENTED, |
| 102 | + ]); |
| 103 | + } |
| 104 | + |
| 105 | + /** |
| 106 | + * Helper method to throw a method not allowed exception. |
| 107 | + * |
| 108 | + * @throws ErrorException |
| 109 | + */ |
| 110 | + public function methodNotAllowed() |
| 111 | + { |
| 112 | + throw new ErrorException([ |
| 113 | + ErrorObjectInterface::TITLE => 'Method Not Allowed', |
| 114 | + ErrorObjectInterface::STATUS => Response::HTTP_METHOD_NOT_ALLOWED, |
| 115 | + ]); |
87 | 116 | }
|
88 | 117 | }
|
0 commit comments