Add common contract schemas and standardized error handling (#543)#575
Open
abhishek-8081 wants to merge 1 commit into
Open
Add common contract schemas and standardized error handling (#543)#575abhishek-8081 wants to merge 1 commit into
abhishek-8081 wants to merge 1 commit into
Conversation
marcvergees
reviewed
Jun 21, 2026
marcvergees
left a comment
Member
There was a problem hiding this comment.
I have added a couple of my thoughts through my code, could you doublecheck it, so that we can therefore merge it?
| report_generation = "report_generation" | ||
|
|
||
|
|
||
| class FormType(str, Enum): |
Member
There was a problem hiding this comment.
For now, we're gonna keep it, but Idk if it's useful in a close future. I know that it was specified in the .yaml by @chetanr25, but I need to doublecheck with the firefighters if they indeed need a field like that.
|
|
||
| # Advisory retry hint on 503 responses — not a measured queue depth or backpressure | ||
| # value; just a safe default so clients know when to try again. | ||
| _RETRY_AFTER_SECONDS = 30 |
Member
There was a problem hiding this comment.
How are we feeling about moving it in the app/core/config.py where we have all the global variables? Feel free to say disagree if you keep thinking that should be here, just lmk.
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.
Closes #543.
Adds the shared contract schemas and standardizes error handling across the app.
Per the discussion on the issue, this is the Option A approach — the new error format
is applied everywhere, including the existing routes, rather than a v1-only split.
New error envelope (per contracts/schemas/common.yaml):
AppErrornow carries anerror_codeand optionaldetail, falling back to astatus-derived code so existing callers keep working.
{error_code, message, detail?, retry_after_seconds?}. A new 422handler maps FastAPI validation errors to the contract's
validation_errorsarray(
field/issue/value).retry_after_secondson 503 is a named advisory constant (30s), commented as aclient hint — not a measured queue depth or backpressure value.
Common schemas: added
ErrorResponse,ValidationErrorItem,Pagination,AsyncJobResponse, andJob(all usingConfigDict), plus all 11 enums fromenums.yamlasstrenums in a newenums.py. The job models use the enumsdirectly rather than plain strings.
Migration of existing routes:
AppErrorraises informs.pynow pass explicit codes (TEMPLATE_NOT_FOUND,FORM_FILL_ERROR,STT_UNAVAILABLE,TRANSCRIPTION_FAILED).templates.pyraisesno
AppError, so it needed no changes.{"error": message}shape and the deadSuccessResponse/ErrorDetail/oldErrorResponseclasses incommon.pyare removed./schemastubs from Health endpoints #542 already matched the envelope, so their PROVISIONALcomments were dropped.
Tests: 36 passing. Updated the one test asserting the old shape, and the 422 test now
verifies the full contract envelope (real
validation_errorsentries, not just astatus code).