Which status code to use when an operation has already been done?

283 Views Asked by At

Users will be able to share images in my project. But let's say that user1 has already shared the image to user2, but user1 tries to share the picture again to user2. What would be the appropriate status code for "already shared"?

2

There are 2 best solutions below

0
Prince Sodhi On

409 is the right status code. It means the item already exists.

In your case "image already shared"

https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/409

0
Keegan Murphy On

I do not believe there a standard convention for this scenario. Status code 409 would highlight the fact the request was 1. Received and understood and 2. There was a server side conflict with processing and storing the data. Some other options would be 400, 403, and 422, but those could mean a variety of other issues with the request that could be misinterpreted.