Skip to content
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

[spiral/exceptions] Ability to Suppress Reporting for Specific Exceptions #984

Closed
butschster opened this issue Sep 6, 2023 · 0 comments · Fixed by #1044
Closed

[spiral/exceptions] Ability to Suppress Reporting for Specific Exceptions #984

butschster opened this issue Sep 6, 2023 · 0 comments · Fixed by #1044

Comments

@butschster
Copy link
Member

It would be great to allow developers to suppress reporting for certain types of exceptions. This would be beneficial for exceptions that are considered "non-critical" or "expected" in some scenarios.

In some applications, exceptions like Spiral\Http\Exception\ClientException may be frequent and expected. However, these aren't always useful to report, especially if using tools like Sentry. Continuously reporting these could clutter the logs and reduce the visibility of more critical exceptions.

Example Implementation:

declare(strict_types=1);

namespace App\Application\Exception;

use Spiral\Exceptions\ExceptionHandler;
use Spiral\Http\Exception\ClientException;

final class Handler extends ExceptionHandler
{
    private array $nonReportableExceptions = [
        ClientException::class,
    ];

    public function report(\Throwable $exception): void
    {
        foreach ($this->nonReportableExceptions as $nonReportableException) {
            if ($exception instanceof $nonReportableException) {
                return;
            }
        }

        parent::report($exception);
    }
}

In the above code, an array $nonReportableExceptions is used to list exceptions that should not be reported. In the report method, we loop through this array to check if the current exception is in the list, and if so, we suppress the report.

@butschster butschster added this to the 3.9 milestone Sep 9, 2023
@butschster butschster self-assigned this Sep 17, 2023
@butschster butschster pinned this issue Sep 17, 2023
@butschster butschster modified the milestones: 3.9, 3.11 Dec 13, 2023
@butschster butschster linked a pull request Jan 3, 2024 that will close this issue
@butschster butschster unpinned this issue May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant