mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-12-05 08:03:01 +00:00
Errors new-api raises itself because of the request no longer count against the channel: - A param override condition that meets a request value of another type (for example a string temperature in a numeric gt rule) now returns a 400 invalid_request that is not retried, instead of channel:param_override_invalid, which was retried on every channel and could auto-disable each of them. Invalid rules that fail every request (non-numeric rule value, unsupported mode) stay channel errors. - Image conversion failures use the shared convert-request-failed error, so they are no longer retried on other channels. - Automatic channel disabling skips errors classified as local by the request policy log, so a local status or a disable keyword echoed from client input cannot disable a channel. Upstream responses that adaptors report as new-api errors, and local wrappers around an upstream error, keep their upstream classification. The logged health entry now uses the same decision.
26 lines
1.0 KiB
Go
26 lines
1.0 KiB
Go
package relay
|
|
|
|
import (
|
|
"errors"
|
|
"net/http"
|
|
|
|
relaycommon "github.com/QuantumNous/new-api/relay/common"
|
|
"github.com/QuantumNous/new-api/relaykit/types"
|
|
)
|
|
|
|
// newAPIErrorFromParamOverride classifies a param override failure by what
|
|
// triggered it. A condition that fails on the request's own value is a 400
|
|
// request error: it neither retries on other channels nor counts against the
|
|
// channel. Other failures come from the channel's override config, which
|
|
// fails for every request, and stay channel errors.
|
|
func newAPIErrorFromParamOverride(err error) *types.NewAPIError {
|
|
if fixedErr, ok := relaycommon.AsParamOverrideReturnError(err); ok {
|
|
return relaycommon.NewAPIErrorFromParamOverride(fixedErr)
|
|
}
|
|
var valueErr *relaycommon.ParamOverrideRequestValueError
|
|
if errors.As(err, &valueErr) {
|
|
return types.NewErrorWithStatusCode(err, types.ErrorCodeInvalidRequest, http.StatusBadRequest, types.ErrOptionWithSkipRetry())
|
|
}
|
|
return types.NewError(err, types.ErrorCodeChannelParamOverrideInvalid, types.ErrOptionWithSkipRetry())
|
|
}
|