mirror of https://github.com/tiangolo/fastapi.git
fix: change status code from 400 to 409
This commit is contained in:
parent
9aad9e3868
commit
552e927686
|
|
@ -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