feat: enhance error handling and validation responses#53
Merged
Conversation
Member
moutonjeremy
commented
Jun 2, 2026
- Introduced custom error handlers for not found and default error shapes.
- Updated OpenAPI spec generation to include custom error types and schemas.
- Changed validation error responses from 400 to 422 to align with RESTful standards.
- Enhanced error envelope structure to provide detailed validation error information.
- Updated tests to reflect new status codes and error handling behavior.
- Introduced custom error handlers for not found and default error shapes. - Updated OpenAPI spec generation to include custom error types and schemas. - Changed validation error responses from 400 to 422 to align with RESTful standards. - Enhanced error envelope structure to provide detailed validation error information. - Updated tests to reflect new status codes and error handling behavior.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR upgrades the library’s default error handling to emit a structured ErrorEnvelope, shifts validation failures to 422 Unprocessable Entity, adds an opt-in not-found catch-all handler (404/405), and enhances OpenAPI generation to document both default envelopes and per-route custom error shapes.
Changes:
- Introduce
ErrorEnvelope/ValidationErrorEntrywith request correlation metadata and richer per-field validation output. - Add
UseNotFoundHandler()+Config.NotFoundHandlerand update OpenAPI generation to include 404 (when installed) plus default 400/422 examples. - Add per-operation
OpenAPIOptions.Errorsto generate concrete status-code responses and schemas; update tests/docs accordingly.
Reviewed changes
Copilot reviewed 21 out of 23 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| validation_test.go | Updates expected validation status codes to 422 and asserts the new envelope shape. |
| types.go | Adds new config knobs (not found + default error shape), and introduces the ErrorEnvelope types. |
| time_type_test.go | Adjusts spec assertions to expect custom TError under the 4XX response key. |
| README.md | Documents the new envelope, status codes, not-found handler, and DefaultErrorShape behavior. |
| put_test.go | Updates PUT validation expectations to 422 and checks envelope/parse error categorization. |
| post_test.go | Updates POST validation expectations to 422 and checks envelope/parse error categorization. |
| json_type_error_test.go | Updates expectations to categorize JSON type mismatches as type_error. |
| header_params_test.go | Updates header validation status to 422. |
| get_oapi_test.go | Updates GET/query validation expectations to 422. |
| fiberoapi.go | Implements new default error behavior, adds OpenAPI error response generation + per-route custom error responses. |
| error_response.go | New implementation for envelope building, request-id/path sanitization, and not-found/405 handling utilities. |
| error_envelope_test.go | New tests validating envelope shape, request-id behavior, not-found handler behavior, and OpenAPI examples. |
| delete_test.go | Updates DELETE validation expectations to 422. |
| default_error_shape_test.go | New tests for DefaultErrorShape behavior at runtime and in generated OpenAPI. |
| custom_validation_error_test.go | Updates default validation behavior tests to match 422 + envelope output. |
| custom_errors.go | New helpers for extracting status/description/schema for declared per-route custom errors. |
| custom_errors_test.go | New tests for per-route error declarations, schema deduplication, and runtime emission. |
| coverage_test.go | Adds focused tests to improve coverage on helper branches and docs endpoints. |
| common.go | Uses wrapped JSON type errors; hardens isZero against nil error interfaces; removes old mismatch detection helpers. |
| _examples/simple_error/main.go | Adds a new example demonstrating per-route errors + DefaultErrorShape. |
| _examples/simple_error/go.mod | Example module setup (with replace) for running the example locally. |
| _examples/simple_error/go.sum | Example dependency lockfile. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.