Commit d5ed4b6a authored by Jacob Priddy's avatar Jacob Priddy 👌

don't need to throw different authentication exception

parent 1b4497fa
......@@ -10,7 +10,9 @@ use Illuminate\Auth\AuthenticationException;
use Source\Exceptions\AuthorizationException;
use Source\Exceptions\EntityNotFoundException;
use Illuminate\Validation\ValidationException;
use Symfony\Component\HttpFoundation\Response;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Source\Exceptions\AuthenticationException as SourceAuthenticationException;
class Handler extends ExceptionHandler {
/**
......@@ -21,6 +23,8 @@ class Handler extends ExceptionHandler {
protected $dontReport = [
EntityNotFoundException::class,
EntityExistsException::class,
SourceAuthenticationException::class,
AuthorizationException::class,
];
/**
......@@ -42,9 +46,9 @@ class Handler extends ExceptionHandler {
/**
* Render an exception into an HTTP response.
*
* @param Request $request
* @param \Exception $exception
* @return \Symfony\Component\HttpFoundation\Response
* @param Request $request
* @param Exception $exception
* @return Response
* @throws Exception
*/
public function render($request, Exception $exception) {
......@@ -55,7 +59,7 @@ class Handler extends ExceptionHandler {
return $this->respondWithError($exception->getMessage(), $exception->getCode());
}
if ($exception instanceof \Source\Exceptions\AuthenticationException) {
if ($exception instanceof SourceAuthenticationException) {
return response()->json(['message' => $exception->getMessage()], 401);
}
......@@ -69,9 +73,9 @@ class Handler extends ExceptionHandler {
/**
* Convert an authentication exception into a response.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Auth\AuthenticationException $exception
* @return \Symfony\Component\HttpFoundation\Response
* @param Request $request
* @param AuthenticationException $exception
* @return Response
*/
protected function unauthenticated($request, AuthenticationException $exception) {
return response()->json(['message' => $exception->getMessage()], 401);
......@@ -80,9 +84,9 @@ class Handler extends ExceptionHandler {
/**
* Create a response object from the given validation exception.
*
* @param \Illuminate\Validation\ValidationException $e
* @param \Illuminate\Http\Request $request
* @return \Symfony\Component\HttpFoundation\Response
* @param ValidationException $e
* @param Request $request
* @return Response
*/
protected function convertValidationExceptionToResponse(ValidationException $e, $request) {
if ($e->response) {
......
......@@ -7,7 +7,6 @@ use Illuminate\Cookie\CookieJar;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Cookie;
use Illuminate\Auth\AuthenticationException;
use Source\Exceptions\AuthenticationException;
use Source\Exceptions\EntityNotFoundException;
use Source\UseCases\Users\Authenticate\APIPresenter;
......@@ -33,11 +32,7 @@ class AuthController extends ApiController {
public function login(AuthenticateUseCase $authenticateUseCase): JsonResponse {
$presenter = new APIPresenter();
try {
$authenticateUseCase->attempt($presenter, $this->request->all());
} catch (AuthenticationException $e) {
throw new AuthenticationException();
}
$authenticateUseCase->attempt($presenter, $this->request->all());
return $this->respondWithData($presenter->getViewModel())->withCookie(
cookie(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment