package gateway import "net/http" // retryableUpstreamStatus reports HTTP codes that should trigger retry / failover. func retryableUpstreamStatus(code int) bool { switch code { case http.StatusTooManyRequests, http.StatusRequestTimeout, http.StatusBadGateway, http.StatusServiceUnavailable, http.StatusGatewayTimeout: return true default: return code >= 500 } } // tryNextKeyOnUpstreamStatus reports auth/rate errors where another provider key may work. func tryNextKeyOnUpstreamStatus(code int) bool { switch code { case http.StatusUnauthorized, http.StatusForbidden, http.StatusTooManyRequests, http.StatusPaymentRequired: return true default: return retryableUpstreamStatus(code) } } // passThroughUpstreamStatus reports client errors that should be returned as-is. func passThroughUpstreamStatus(code int) bool { switch code { case http.StatusBadRequest, http.StatusNotFound, http.StatusUnprocessableEntity, http.StatusUnsupportedMediaType: return true default: return false } }