Skip to content

Add method to be able to override the exception context format - #44895

Merged
taylorotwell merged 4 commits into
laravel:9.xfrom
halnique:feat/exception-handler-context-format
Nov 10, 2022
Merged

taylorotwell merged 4 commits into
laravel:9.xfrom
halnique:feat/exception-handler-context-format

Conversation

@halnique

Copy link
Copy Markdown
Contributor

This PR extracted 1 protected methods to Illuminate\Foundation\Exceptions\Handler to override exception context format in downstream.

Currently if you need to customize context format of an exception, you would need to override the whole report method and do it there.

Adding this method allows us to customize context format of an exception by simply implementing the method in the applications Handler class. This is not a breaking change.

Example:

    // override
    protected function buildContext(Throwable $e): array
    {
        return [
            'exception' => [
                'origin' => $e,
                'context' => [
                    'common' => $this->context(),
                    'specific' => $this->exceptionContext($e),
                ],
            ],
        ];
    }

@taylorotwell
taylorotwell merged commit 527b288 into laravel:9.x Nov 10, 2022
@halnique
halnique deleted the feat/exception-handler-context-format branch November 11, 2022 01:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants