10000 Update exceptions in controller. · JerseyPostAtlas/laravel-json-api@0d370df · GitHub
[go: up one dir, main page]

Skip to content

Commit 0d370df

Browse files
committed
Update exceptions in controller.
1 parent 3202481 commit 0d370df

File tree

1 file changed

+37
-8
lines changed

1 file changed

+37
-8
lines changed

src/Http/Controllers/JsonApiController.php

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818

1919
namespace CloudCreativity\JsonApi\Http\Controllers;
2020

21-
use CloudCreativity\JsonApi\Error\ThrowableError;
21+
use CloudCreativity\JsonApi\Contracts\Error\ErrorObjectInterface;
22+
use CloudCreativity\JsonApi\Error\ErrorException;
2223
use Illuminate\Http\Response;
2324
use Illuminate\Routing\Controller;
2425

@@ -57,32 +58,60 @@ public function callAction($method, $parameters)
5758
/**
5859
* @param array $parameters
5960
* @return void
60-
* @throws ThrowableError
61+
* @throws ErrorException
6162
*/
6263
public function missingMethod($parameters = [])
6364
{
64-
throw new ThrowableError('Method Not Allowed', Response::HTTP_METHOD_NOT_ALLOWED);
65+
$this->methodNotAllowed();
6566
}
6667

6768
/**
6869
* @param string $method
6970
* @param array $parameters
7071
* @return void
71-
* @throws ThrowableError
72+
* @throws ErrorException
7273
*/
7374
public function __call($method, $parameters)
7475
{
75-
throw new ThrowableError('Not Implemented', Response::HTTP_NOT_IMPLEMENTED);
76+
$this->notImplemented();
7677
}
7778

7879
/**
7980
* Helper method to throw a not found exception.
8081
*
81-
* @return void
82-
* @throws ThrowableError
82+
* @throws ErrorException
8383
*/
8484
public function notFound()
8585
{
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+
]);
87116
}
88117
}

0 commit comments

Comments
 (0)
0