mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-08-20 12:00:32 +08:00
feat: add OasstErrorResponse to protocols
Using a shared protocol to serialize the error in the backend allows clients to use that same protocol to deserialize it. Changes to this protocol will be caught in tests.
This commit is contained in:
+6
-1
@@ -26,8 +26,13 @@ app = fastapi.FastAPI(title=settings.PROJECT_NAME, openapi_url=f"{settings.API_V
|
||||
@app.exception_handler(OasstError)
|
||||
async def oasst_exception_handler(request: fastapi.Request, ex: OasstError):
|
||||
logger.error(f"{request.method} {request.url} failed: {repr(ex)}")
|
||||
|
||||
return fastapi.responses.JSONResponse(
|
||||
status_code=int(ex.http_status_code), content={"message": ex.message, "error_code": ex.error_code}
|
||||
status_code=int(ex.http_status_code),
|
||||
content=protocol_schema.OasstErrorResponse(
|
||||
message=ex.message,
|
||||
error_code=OasstErrorCode(ex.error_code),
|
||||
).dict(),
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user