fix: inherit App error catalogs on generated routes without local errors

This commit is contained in:
2026-09-24 15:42:03 +08:00
parent bca2ef92cc
commit a2a07a39ea
21 changed files with 570 additions and 54 deletions

View File

@@ -26,7 +26,9 @@ func (e *errorEncoder) Encode(r Result) (Payload, error) {
// WithErrors binds a catalog to an encoder without imposing a response shape.
// Built-in templates are checked for incompatible code types and conflicting
// legacy mappings. Custom encoders remain responsible for their wire contract.
// legacy mappings. An empty catalog leaves next unchanged, so Context can
// inherit its App catalog without a second, empty lookup during encoding.
// Custom encoders remain responsible for their wire contract.
func WithErrors(catalog apierrors.Catalog, next Encoder) (Encoder, error) {
registry, err := apierrors.NewRegistry(catalog)
if err != nil {
@@ -35,10 +37,10 @@ func WithErrors(catalog apierrors.Catalog, next Encoder) (Encoder, error) {
if next == nil {
next = Default()
}
if len(catalog.Definitions) == 0 {
return next, nil
}
if provider, ok := next.(ErrorRegistryProvider); ok && provider.ErrorRegistry() != nil {
if len(catalog.Definitions) == 0 {
return next, nil
}
if reflect.DeepEqual(registry.Catalog(), provider.ErrorRegistry().Catalog()) {
return next, nil
}