-
-
Notifications
You must be signed in to change notification settings - Fork 438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make reporting of client-safe errors configurable #2647
Make reporting of client-safe errors configurable #2647
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not fully convinced that a configuration option at that level is the best option. The problem I see with this approach is that its value is only used from within ReportingErrorHandler
, which is configurable in itself. Thus, for users that omit or replace ReportingErrorHandler
, the option report_client_safe_errors
has no effect.
That's a valid concern. Would you perhaps prefer to solve this on the // app/Providers/GraphQLServiceProvider.php
public function boot(): void
{
ReportingErrorHandler::reportClientSafeErrors();
} I'm not always keen on static config, but it does fit Laravel's way of working. Another option could be to bind it to the container and extend the instance when resolving it: // app/Providers/GraphQLServiceProvider.php
public function boot(): void
{
$this->app->extend(ReportingErrorHandler::class, fn (ReportingErrorHandler $errorHandler) => $errorHandler->reportClientSafeErrors());
} This requires some more code, but removes the static context. |
Or perhaps we could solve this through a named constructor on the // config/lighthouse.php
return [
'error_handlers' => [
[Nuwave\Lighthouse\Execution\ReportingErrorHandler::class, 'includeClientSafeErrors'],
// or...
Nuwave\Lighthouse\Execution\ReportingErrorHandler::class . '@includeClientSafeErrors',
],
]; |
Another option would be to add a new class to replace |
Sure, that might work too. On it. |
Thank you @remipelhate, released with https://github.com/nuwave/lighthouse/releases/tag/v6.49.0. |
Changes
While it makes perfect sense to not pass client safe errors to Laravel's exception handler by default, in some cases, it can be useful to be able to do so.
Laravel allows to define a minimum log level at which each individual log channel is invoked. For example,
sentry
can be set to only report errors with a minimum level ofwarning
, whereasslack
only gets triggered as ofcritical
:I've used this setup for a project where the team wanted to be able to track all authentication and authorization exceptions in Prometheus, as those can give insights on potential ACL issues or misuse. The problem is that Lighthouse marks these errors as client safe, causing them not to be passed to Laravel's exception handler.
This PR introduces a new
Nuwave\Lighthouse\Execution\AlwaysReportingErrorHandler
which can be used instead ofNuwave\Lighthouse\Execution\ReportingErrorHandler
in thelighthouse.php
config:When using
Nuwave\Lighthouse\Execution\AlwaysReportingErrorHandler
, client-safe exceptions will be passed to thedefault Laravel exception handler, allowing you to configure appropriate error reporting outside of Lighthouse.
Breaking changes
No