halo-dev / halo

强大易用的开源建站工具。
https://www.halo.run
GNU General Public License v3.0
32.47k stars 9.45k forks source link

Respond status 409 (Conflict) for optimistic locking error instead of status 500 #6254

Closed JohnNiang closed 11 hours ago

JohnNiang commented 3 days ago

Your current Halo version

2.17.0-SNAPSHOT

Describe this feature

Currently, if there is a conflict in the operation, Halo will respond with status 500, which is a confusion for end users. e.g.:

{
  "type": "about:blank",
  "title": "Internal Server Error",
  "status": 500,
  "detail": "Something went wrong, please try again later.",
  "instance": "http://halo:8090/apis/api.console.halo.run/v1alpha1/users/bnmJqS/password",
  "requestId": "f3fea404-10",
  "timestamp": "2024-06-21T01:49:03.746356448Z"
}

IMO, it's more reasonable to respond 409 (Conflict) in that situation. e.g.:

{
  "type": "https://www.halo.run/probs/operation-conflict",
  "title": "Operation Conflict",
  "status": 409,
  "detail": "Operation conflict detected, please try again.",
  "instance": "http://halo:8090/apis/api.console.halo.run/v1alpha1/users/bnmJqS/password",
  "requestId": "f3fea404-10",
  "timestamp": "2024-06-21T01:49:03.746356448Z"
}

Additional information

/kind improvement /area core /milestone 2.18.x

JohnNiang commented 2 days ago

/assign