Repository navigation
feat: handle exceptions globally and add health checks - #30
Merged
Merged
Conversation
Each consuming API wrapped every controller action in the same try/catch ladder. The handler now turns any exception that leaves an action into an RFC 7807 response. The defaults map a missing entity to 404, a failed entity validation to 400 with the entityKey the batch editors read, and a missing permission to 403. Applications add or override mappings in one place. The code comes from Zilia.Apps.Core, which only Zilia applications can use. It reports faults through a new IExceptionReporter instead of a Zilia-specific service. A breadcrumb filter keeps the action's arguments in the report, the context the removed catch blocks used to send. Health checks come with it: /health answers without touching the database, and /health/ready checks that the database answers. ZWebAPI now references the ASP.NET Core shared framework. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
🎉 This PR is included in version 1.16.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Consuming APIs wrap every controller action in the same try/catch ladder. Zilia applications got a global handler and health checks from Zilia.Apps.Core, which other applications cannot use. This brings both into ZWebAPI so the Niten APIs can drop their catch blocks.
What changes
AddGlobalExceptionHandling/UseGlobalExceptionHandlingturn any exception that leaves an action into an RFC 7807 response.EntityNotFoundException<T>, 400 withentityKeyforEntityValidationFailureException<TKey>, 403 forMissingUserPermissionException, 500 for anything else.Map<T>. A mapping matches the exact type, then an open generic, then each base type.IExceptionReporterthe application registers; its error id is written aserrorId. Exception detail is written only in Development, and only when enabled.ActionArgumentsBreadcrumbFilter, registered with the handler, sends the action's arguments with the report. This is the context the removed catch blocks used to add.AddDefaultHealthChecks/MapDefaultHealthChecks:/healthruns no check,/health/readychecks that the database answers.The handler, options and health check are ported from Zilia.Apps.Core, with neutral names and the reporter interface in place of its Zilia-specific service.
Testing
dotnet testpasses on net8.0, net9.0 and net10.0 (293 tests), including new tests for the options, the handler, the filter and the health check.🤖 Generated with Claude Code