Skip to content

feat: enhance error handling and validation responses#53

Merged
moutonjeremy merged 9 commits into
mainfrom
error-response-improvment
Jun 2, 2026
Merged

feat: enhance error handling and validation responses#53
moutonjeremy merged 9 commits into
mainfrom
error-response-improvment

Conversation

@moutonjeremy
Copy link
Copy Markdown
Member

  • 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.
Copilot AI review requested due to automatic review settings June 2, 2026 13:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 / ValidationErrorEntry with request correlation metadata and richer per-field validation output.
  • Add UseNotFoundHandler() + Config.NotFoundHandler and update OpenAPI generation to include 404 (when installed) plus default 400/422 examples.
  • Add per-operation OpenAPIOptions.Errors to 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.

Comment thread fiberoapi.go
Comment thread fiberoapi.go
Comment thread error_response.go
Comment thread error_response.go Outdated
Comment thread types.go
Comment thread types.go Outdated
Comment thread README.md Outdated
Comment thread _examples/simple_error/main.go Outdated
moutonjeremy and others added 6 commits June 2, 2026 16:08
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>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 22 out of 24 changed files in this pull request and generated 6 comments.

Comment thread error_response.go
Comment thread types.go
Comment thread error_response.go Outdated
Comment thread README.md Outdated
Comment thread README.md Outdated
Comment thread custom_errors.go Outdated
@moutonjeremy moutonjeremy merged commit f35e45b into main Jun 2, 2026
4 checks passed
@moutonjeremy moutonjeremy deleted the error-response-improvment branch June 2, 2026 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants