update to include JSON indicating request already handled

This commit is contained in:
kim 2024-08-09 12:55:25 +01:00
parent fd2be943b7
commit 53fcea5751

View file

@ -32,6 +32,14 @@
// https://datatracker.ietf.org/doc/draft-ietf-httpapi-idempotency-key-header/
func Idempotency() gin.HandlerFunc {
// Prepare response given when request already handled.
alreadyHandled, err := json.Marshal(map[string]string{
"status": "request already handled",
})
if err != nil {
panic(err)
}
// Prepare expected error response JSON ahead of time.
errorConflict, err := json.Marshal(map[string]string{
"error": "request already under way",
@ -96,7 +104,11 @@ func Idempotency() gin.HandlerFunc {
// Already handled
// this request.
default:
c.Status(code)
apiutil.Data(c,
code,
apiutil.AppJSON,
alreadyHandled,
)
return
}