Skip to content

Commit

Permalink
Add better error messages for fallback providers
Browse files Browse the repository at this point in the history
  • Loading branch information
therealjmj committed Jun 9, 2023
1 parent d674d4c commit b849bea
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/utils/fallback-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ export const createFallbackProviderFromJsonConfig = (
config: FallbackProviderJsonConfig,
): FallbackProvider => {
try {
const totalWeight = config.providers.reduce(
(acc, { weight }) => acc + weight,
0,
);
if (totalWeight < 2) {
throw new Error(
'Total weight across providers must be >= 2 for fallback quorum.',
);
}

const network = Network.from(Number(config.chainId));

const providers: FallbackProviderConfig[] = config.providers.map(
Expand Down Expand Up @@ -49,6 +59,8 @@ export const createFallbackProviderFromJsonConfig = (
if (!(err instanceof Error)) {
throw err;
}
throw new Error(`Invalid fallback provider config: ${err.message}`);
throw new Error(
`Invalid fallback provider config for chain ${config.chainId}: ${err.message}`,
);
}
};

0 comments on commit b849bea

Please sign in to comment.