Skip to content

Breaks self rendering exceptions (contains render method) #154

@4n70w4

Description

@4n70w4

Hi! I also really hate Laravel's native exception handler.

Laravel Nova contain AuthenticationException with render method https://gist.github.com/4n70w4/3e17c2df500527be3f603c32ab7e2762

Switching to this library completely breaks the work of the Nova.

Also I found ~ 3 500 similar exceptions with render method on github.

All of them will not rendered correctly when using this library.

https://github.com/search?p=5&q=%5CIlluminate%5CHttp%5CResponse+%22function+render%28%24request%29%22+NOT+Handler+%26+NOT+OAuthServerException+extension%3Aphp+filename%3AException&type=Code

I know that you are extremely against the changes in the method \GrahamCampbell\Exceptions\ExceptionHandler::render

However, the easiest way is to make this change.

Replace

$response = $e instanceof Responsable ? $e->toResponse($request) : null;

to

        if (method_exists($e, 'render') && $response = $e->render($request)) {
            $response = $this->container->get(Router::class)->toResponse($request, $response);
        } elseif ($e instanceof Responsable) {
            $response = $e->toResponse($request);
        } else {
            $response = null;
        }

Alternatively, can make a separate displayer for this. My example implementation: https://gist.github.com/4n70w4/39cc0441eea9c6b94512ff2443009bf8

This is a very common scenario. I don't understand why it is not included in this library.

Switching to this library breaks some components. It is sad.
Many people will have to do the same job over and over to solve this problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions