Currently exceptions only return JSON responses. The Exceptions needs to determine the request type and decide to return JSON data or WEB view.
Hi...
I have been writing some tests for fix some bugs and features on the Web Authentication container, would be great to have this fixed to get better error display formatting on web routes. I tried to fix it, but was very confusing to me searching where the exceptions are triggered on web requests. Even try/catch on Task didn't work, the exception is ever triggered.
Thanks!!
Excuse me, try/catch works, I forgot include the exception class namespace on the controller. It's a ugly way but until the fix arrives, it would be like this:
<?php
namespace App\Containers\Authentication\UI\WEB\Controllers;
// ...
use App\Containers\Authentication\Exceptions\AuthenticationFailedException;
class Controller extends PortWebController
{
public function loginAdmin(LoginRequest $request, WebAdminLoginAction $action)
{
try {
$result = $action->run($request->email, $request->password, $request->remember_me);
} catch (AuthenticationFailedException $e) {
return redirect('/login')->with('status', $e->message);
}
if (is_array($result)) {
return redirect('/login')->with($result);
}
return redirect('/dashboard');
}
}
Off course, Form Requests still fail, no way to prevent it, unless we made validations within controller, but doesn't follow the PORTO conventions and is ugly++, jejeje.
@llstarscreamll this is related to the Dingo API package, because they override the default Laravel Exception rendering.
I tried adding something like this:
if (!$request->expectsJson()) {
return app()->make(\Illuminate\Foundation\Exceptions\Handler::class)->render($request, $exception);
}
in the render() function but didn't worked, I didn't spend enough time on it.
Hi @Mahmoudz,
I have now correct web errors by setting API_PREFIX=api on the .env file, based on this Laracast question. I have tried 500 error from now, since there is a problem with Session on web routes and can't do much...
Hi @Mahmoudz, I have found a solution for this issue by making a small change on the app/Ship/Parents/Requests/RequestTrait.php and setting API_PREFIX=api, I have the PR ready but #115 should be merged first...
@llstarscreamll thank you man, I've merged your first PR, you're free to send this one anytime.
closed by #116