handles 'this organization is disabled' error from anthropic
This commit is contained in:
parent
ddf34685df
commit
8f46bd4397
|
@ -450,6 +450,17 @@ async function handleAnthropicBadRequestError(
|
|||
return;
|
||||
}
|
||||
|
||||
const isDisabled = error?.message?.match(/organization has been disabled/i);
|
||||
if (isDisabled) {
|
||||
req.log.warn(
|
||||
{ key: req.key?.hash, message: error?.message },
|
||||
"Anthropic key has been disabled."
|
||||
);
|
||||
keyPool.disable(req.key!, "revoked");
|
||||
errorPayload.proxy_note = `Assigned key has been disabled. ${error?.message}`;
|
||||
return;
|
||||
}
|
||||
|
||||
errorPayload.proxy_note = `Unrecognized error from the API. (${error?.message})`;
|
||||
}
|
||||
|
||||
|
|
|
@ -61,15 +61,26 @@ export class AnthropicKeyChecker extends KeyCheckerBase<AnthropicKey> {
|
|||
protected handleAxiosError(key: AnthropicKey, error: AxiosError) {
|
||||
if (error.response && AnthropicKeyChecker.errorIsAnthropicAPIError(error)) {
|
||||
const { status, data } = error.response;
|
||||
// They send billing/revocation errors as 400s for some reason.
|
||||
// The type is always invalid_request_error, so we have to check the text.
|
||||
const isOverQuota =
|
||||
data.error?.message?.match(/usage blocked until/i) ||
|
||||
data.error?.message?.match(/credit balance is too low/i);
|
||||
const isDisabled = data.error?.message?.match(
|
||||
/organization has been disabled/i
|
||||
);
|
||||
if (status === 400 && isOverQuota) {
|
||||
this.log.warn(
|
||||
{ key: key.hash, error: data },
|
||||
"Key is over quota. Disabling key."
|
||||
);
|
||||
this.updateKey(key.hash, { isDisabled: true, isOverQuota: true });
|
||||
} else if (status === 400 && isDisabled) {
|
||||
this.log.warn(
|
||||
{ key: key.hash, error: data },
|
||||
"Key's organization is disabled. Disabling key."
|
||||
);
|
||||
this.updateKey(key.hash, { isDisabled: true, isRevoked: true });
|
||||
} else if (status === 401 || status === 403) {
|
||||
this.log.warn(
|
||||
{ key: key.hash, error: data },
|
||||
|
|
Loading…
Reference in New Issue