mirror of https://github.com/tiangolo/fastapi.git
docs: fix inconsistent response code when item already exists
In https://github.com/tiangolo/fastapi/pull/4482, the response status code was changed to return 409 when the item already exists in non-Annotated examples, but left as 400 in the others. Seems like an oversight, unless this was done intentionally for a reason I'm not aware of.
This commit is contained in:
parent
912524233b
commit
f3c1a2d592
|
|
@ -34,6 +34,6 @@ async def create_item(item: Item, x_token: Annotated[str, Header()]):
|
|||
if x_token != fake_secret_token:
|
||||
raise HTTPException(status_code=400, detail="Invalid X-Token header")
|
||||
if item.id in fake_db:
|
||||
raise HTTPException(status_code=400, detail="Item already exists")
|
||||
raise HTTPException(status_code=409, detail="Item already exists")
|
||||
fake_db[item.id] = item
|
||||
return item
|
||||
|
|
|
|||
|
|
@ -61,5 +61,5 @@ def test_create_existing_item():
|
|||
"description": "There goes my stealer",
|
||||
},
|
||||
)
|
||||
assert response.status_code == 400
|
||||
assert response.status_code == 409
|
||||
assert response.json() == {"detail": "Item already exists"}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,6 @@ async def create_item(item: Item, x_token: Annotated[str, Header()]):
|
|||
if x_token != fake_secret_token:
|
||||
raise HTTPException(status_code=400, detail="Invalid X-Token header")
|
||||
if item.id in fake_db:
|
||||
raise HTTPException(status_code=400, detail="Item already exists")
|
||||
raise HTTPException(status_code=409, detail="Item already exists")
|
||||
fake_db[item.id] = item
|
||||
return item
|
||||
|
|
|
|||
|
|
@ -61,5 +61,5 @@ def test_create_existing_item():
|
|||
"description": "There goes my stealer",
|
||||
},
|
||||
)
|
||||
assert response.status_code == 400
|
||||
assert response.status_code == 409
|
||||
assert response.json() == {"detail": "Item already exists"}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,6 @@ async def create_item(item: Item, x_token: Annotated[str, Header()]):
|
|||
if x_token != fake_secret_token:
|
||||
raise HTTPException(status_code=400, detail="Invalid X-Token header")
|
||||
if item.id in fake_db:
|
||||
raise HTTPException(status_code=400, detail="Item already exists")
|
||||
raise HTTPException(status_code=409, detail="Item already exists")
|
||||
fake_db[item.id] = item
|
||||
return item
|
||||
|
|
|
|||
|
|
@ -61,5 +61,5 @@ def test_create_existing_item():
|
|||
"description": "There goes my stealer",
|
||||
},
|
||||
)
|
||||
assert response.status_code == 400
|
||||
assert response.status_code == 409
|
||||
assert response.json() == {"detail": "Item already exists"}
|
||||
|
|
|
|||
Loading…
Reference in New Issue