Replies: 1 comment 3 replies
-
I feel this could be better solved with say, an interface Identifiable
{
public function getErrorId(): string;
} Exceptions can then implement this method. The exception handler then has an interface to look for rather than iterating over the debug backtrace and also changing the current behaviour of |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Proposal
When reporting an exception in the exception handler. The reporter callable could return a string designed to be a unique identifier for the error that occurred. This identifier could then be displayed to the end user as an error code in a view or API response to send to a company's technical support to help diagnose an issue.
Why
Services like Sentry automatically produce a unique event ID for every exception reported. It would be a neat feature of Laravel to be able to show error IDs out of the box when an event ID is set. The benefit would be that it's easier for companies to tie together application failures from the end user to diagnostic tools like Sentry.
It feels like this is a no-brainer for modern web applications to be able to provide feedback via a unique code to end users when an error occurs and something every production application could make use of.
Those working with the likes of SPAs will need to handle how to display the error from a JSON response.
Example Usage
The report callbacks would behave in the same similar way except that a string could be returned which would set the error ID to be displayed.
Possible Implementation
The following covers the basics required. I've not included things like updating the 500 error view as such a change would be more design-focused.
Notes
Shouldn't be a breaking change for most people in returning a string value but it is possible. The other alternative I can think of is passing a callable as a second parameter to the report callable that allows the user to specifically set properties to add to JSON or view responses and that way developers could extend the functionality in a way they felt fit and possibly have multiple reporters set different values into the response.
e.g.
I'm happy to implement the feature, would just rather have the thumbs up that the idea is wanted before putting in the time for it. I could see this being added to Laravel 10 or 11 with minimal fuss.
Thanks for reading!
Beta Was this translation helpful? Give feedback.
All reactions