Skip to content

Commit

Permalink
Replace message with detail in error JSON (#603)
Browse files Browse the repository at this point in the history
  • Loading branch information
meln1k authored Aug 28, 2024
1 parent f9bab03 commit 99a2b42
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions fixbackend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,31 +180,31 @@ async def add_logging_context(request: Request, call_next: Callable[[Request], A

@app.exception_handler(NotAllowed)
async def access_denied_handler(_: Request, exception: NotAllowed) -> Response:
return JSONResponse(status_code=403, content={"message": str(exception)})
return JSONResponse(status_code=403, content={"detail": str(exception)})

@app.exception_handler(ResourceNotFound)
async def resource_not_found_handler(_: Request, exception: ResourceNotFound) -> Response:
return JSONResponse(status_code=404, content={"message": str(exception)})
return JSONResponse(status_code=404, content={"detail": str(exception)})

@app.exception_handler(InventoryException)
async def inventory_exception_handler(_: Request, exception: InventoryException) -> Response:
return JSONResponse(status_code=exception.status, content={"message": str(exception)})
return JSONResponse(status_code=exception.status, content={"detail": str(exception)})

@app.exception_handler(WrongState)
async def wrong_state_handler(_: Request, exception: WrongState) -> Response:
return JSONResponse(status_code=409, content={"message": str(exception)})
return JSONResponse(status_code=409, content={"detail": str(exception)})

@app.exception_handler(ClientError)
async def client_error_handler(_: Request, exception: ClientError) -> Response:
return JSONResponse(status_code=400, content={"message": str(exception)})
return JSONResponse(status_code=400, content={"detail": str(exception)})

@app.exception_handler(AssertionError)
async def invalid_data(_: Request, exception: AssertionError) -> Response:
return JSONResponse({"detail": str(exception)}, status_code=422)

@app.exception_handler(FastAPIUsersException)
async def fastapi_users_handler(_: Request, exception: FastAPIUsersException) -> Response:
return JSONResponse(status_code=400, content={"message": "invalid user"})
return JSONResponse(status_code=400, content={"detail": "invalid user"})

class EndpointFilter(logging.Filter):
endpoints_to_filter: ClassVar[Set[str]] = {
Expand Down

0 comments on commit 99a2b42

Please sign in to comment.