mirror of
https://github.com/morluto/rea.git
synced 2026-11-15 19:23:24 +00:00
49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
import {
|
|
AnalysisInputError,
|
|
AnalysisResourceConstraintError,
|
|
} from "./analysisErrorCore.js";
|
|
import type { AnalysisError } from "./analysisErrorBase.js";
|
|
import type { AnalysisRefusal } from "./analysisRefusal.js";
|
|
|
|
/**
|
|
* The typed refusal an error carries, attributed to the error's operation so
|
|
* a re-attributed error names the request that was refused. Occupied capacity
|
|
* keeps its wait-and-retry recovery even when a setting bounds it.
|
|
*/
|
|
export const analysisErrorRefusal = (
|
|
error: AnalysisError,
|
|
): AnalysisRefusal | undefined => {
|
|
if (error instanceof AnalysisResourceConstraintError) {
|
|
if (error.fixedAllowance !== undefined)
|
|
return {
|
|
kind: "fixed_ceiling",
|
|
operation: error.operation,
|
|
ceiling: error.fixedAllowance,
|
|
};
|
|
if (
|
|
error.limit !== undefined &&
|
|
!("control_kind" in error.limit) &&
|
|
!(
|
|
"measuredExhaustion" in error.recovery &&
|
|
error.recovery.measuredExhaustion === true
|
|
)
|
|
)
|
|
return {
|
|
kind: "adjustable_budget",
|
|
operation: error.operation,
|
|
budget: error.limit,
|
|
};
|
|
return undefined;
|
|
}
|
|
if (
|
|
error instanceof AnalysisInputError &&
|
|
error.ambiguousSelector !== undefined
|
|
)
|
|
return {
|
|
kind: "ambiguous_selector",
|
|
operation: error.operation,
|
|
selector: error.ambiguousSelector,
|
|
};
|
|
return undefined;
|
|
};
|