You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
chajia/lib/rpa/direct-quote-fallback.ts

27 lines
835 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import { RpaError, NO_RETRY_CODES } from "@/modules/rpa/errors";
import { isWidgetQuoteFallbackEnabled } from "@/lib/rpa/env";
/**
* axel 直连报「无运力」时Widget 浏览器链路仍可能出价的线路(如 sign-up-quote Tab 读价)。
*/
export function shouldFallbackToWidgetAfterDirectError(error: unknown): boolean {
if (!isWidgetQuoteFallbackEnabled()) {
return false;
}
return error instanceof RpaError && error.code === "CARRIER_NO_CAPACITY";
}
/** direct 失败是否应直接终止(不走 Widget */
export function isDirectErrorFatalWithoutWidget(error: unknown): boolean {
if (!(error instanceof RpaError)) {
return false;
}
if (!NO_RETRY_CODES.has(error.code)) {
return false;
}
if (shouldFallbackToWidgetAfterDirectError(error)) {
return false;
}
return true;
}