Skip to content

Refactor/api-error-spec#347

Merged
nycomp merged 11 commits intoweeklyfrom
refactor/api-error-spec
Feb 9, 2026
Merged

Refactor/api-error-spec#347
nycomp merged 11 commits intoweeklyfrom
refactor/api-error-spec

Conversation

@nycomp
Copy link
Contributor

@nycomp nycomp commented Feb 9, 2026

Phase 6 of API Error Specification implementation:

Documentation:

  • Add OpenAPI 3.0 spec at campus/api/docs/openapi.yaml
  • Define ErrorEnvelope, Error, ValidationError, and FieldError schemas
  • Add reusable error response objects (400, 401, 403, 404, 409, 422, 500)
  • Include error code documentation and examples
  • Remove migration guide from refactor plan (no users yet, campus in dev)

All phases now complete:

  • Phase 1: Core error structure ✅
  • Phase 2: Validation error structure ✅
  • Phase 3: Update validation code ✅
  • Phase 4: Add error response tests ✅
  • Phase 5: Client-side updates ✅
  • Phase 6: Documentation ✅

Reference: campus/api/docs/api-error-spec.md

Co-Authored-By: Claude Opus 4.5 noreply@anthropic.com

ngjunsiang and others added 11 commits February 5, 2026 10:20
Add comprehensive error response specification for campus API.
Defines error envelope structure, validation error format,
and environment-specific behavior for debug information.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Implement spec-compliant error envelope structure for all API error responses.

Changes:
- Update ErrorConstant enum: add INTERNAL_ERROR, VALIDATION_FAILED
- Update APIError.to_dict() to return nested error envelope:
  {"error": {"code": "...", "message": "...", "details": {}, "request_id": null}}
- Update InternalError to use INTERNAL_ERROR constant
- Update error handlers to remove nested details in production
- Update all contract tests to assert new error format
- Update contract test README documentation

Breaking change: Error responses now use nested structure.
Old: {"error_code": "UNAUTHORIZED", "message": "...", "details": {}}
New: {"error": {"code": "UNAUTHORIZED", "message": "...", "details": {}, "request_id": null}}

Reference: campus/api/docs/api-error-spec.md

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add comprehensive phased implementation plan for the error handling
specification refactor. Phase 1 is already complete.

Reference: campus/api/docs/api-error-spec-refactor-plan.md

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…Phase 2

Add FieldError TypedDict and ValidationError class (status 422) with
to_dict() that adds errors array to error envelope.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
… Phase 3

- Update unpack_into to collect field errors instead of raising KeyError
- Raise ValidationError with structured FieldError objects for missing params
- Update refactor plan to mark Phase 3 complete

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Mark Phase 3 as complete with commit reference
- Mark Phase 3.2 as deferred
- Update test command to use Poetry and run_tests.py
- Document test results

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add comprehensive test coverage for API error specification compliance:
- TestErrorEnvelope: verifies all error types have correct envelope structure
- TestValidationErrors: tests ValidationError with field-level errors
- TestErrorCodes: validates error code format (UPPER_SNAKE_CASE) and mapping
- TestEnvironmentSpecificBehavior: tests dev vs prod behavior for tracebacks

All 103 unit tests and 18 integration tests pass.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Phase 5 (Client-side updates for campus-api-python) is now complete:
- Added FieldError and ValidationError classes to client
- Updated APIError with request_id, details, errors, notes fields
- Updated with_status_code() to parse new error envelope format
- Added backward compatibility for legacy error format
- Added 17 tests for error parsing

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Phase 6 of API Error Specification implementation:

Documentation:
- Add OpenAPI 3.0 spec at campus/api/docs/openapi.yaml
- Define ErrorEnvelope, Error, ValidationError, and FieldError schemas
- Add reusable error response objects (400, 401, 403, 404, 409, 422, 500)
- Include error code documentation and examples
- Remove migration guide from refactor plan (no users yet, campus in dev)

All phases now complete:
- Phase 1: Core error structure ✅
- Phase 2: Validation error structure ✅
- Phase 3: Update validation code ✅
- Phase 4: Add error response tests ✅
- Phase 5: Client-side updates ✅
- Phase 6: Documentation ✅

Reference: campus/api/docs/api-error-spec.md

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@nycomp nycomp added this to the Campus Timetable API milestone Feb 9, 2026
@nycomp nycomp merged commit 49380a7 into weekly Feb 9, 2026
4 checks passed
@nycomp nycomp deleted the refactor/api-error-spec branch February 9, 2026 08:05
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

Comments