Skip to content

Conversation

@avrahamappel
Copy link
Contributor

@avrahamappel avrahamappel commented Mar 1, 2021

Currently, in order to send custom context to the logger on a per-exception basis, it is necessary to override the exceptionContext method in App\Exceptions\Handler and check the exception instance. This PR enables the base Handler to detect a context method defined on the exception class which would return an array, keeping the context logic within the exception class.

class InvalidOrderException extends Exception
{
    /**
     * Provide exception context.
     *
     * @return array
     */
     public function context()
     {
         return ['id' => $this->order->id];
     }
}

Once this is merged, I can make a PR to the docs demonstrating this.

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