fix: update the concurrency middleware to respond with a JSON payload (#798)
update the concurrency middleware to respond with a JSON payload instead of plain text when the request limit is reached to be compatible with openai api standard --------- Co-authored-by: Ludwik <l.czarnota@samsung.com>
This commit is contained in:
@@ -45,7 +45,9 @@ func CreateConcurrencyMiddleware(cfg config.Config) chain.Middleware {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !sem.TryAcquire(1) {
|
if !sem.TryAcquire(1) {
|
||||||
http.Error(w, "Too many requests", http.StatusTooManyRequests)
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.WriteHeader(http.StatusTooManyRequests)
|
||||||
|
w.Write([]byte(`{"error":"Too many requests"}`))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer sem.Release(1)
|
defer sem.Release(1)
|
||||||
|
|||||||
Reference in New Issue
Block a user