mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-01 09:29:38 +02:00
Narrow provider status errors with Predicate
This commit is contained in:
parent
b3aaa9a4af
commit
b51dc33786
3 changed files with 39 additions and 6 deletions
|
|
@ -5,6 +5,7 @@ import {
|
|||
} from "@trustgraph/base";
|
||||
import { Config, Effect } from "effect";
|
||||
import * as O from "effect/Option";
|
||||
import * as Predicate from "effect/Predicate";
|
||||
import * as S from "effect/Schema";
|
||||
|
||||
export class TextCompletionConfigError extends S.TaggedErrorClass<TextCompletionConfigError>()(
|
||||
|
|
@ -68,11 +69,11 @@ export const providerStatusError = (
|
|||
provider: string,
|
||||
error: unknown,
|
||||
): TextCompletionRuntimeError => {
|
||||
const status = typeof error === "object" && error !== null && "status" in error
|
||||
? (error as { readonly status?: unknown }).status
|
||||
const status = Predicate.isObject(error) && Predicate.hasProperty(error, "status")
|
||||
? error.status
|
||||
: undefined;
|
||||
const statusCode = typeof error === "object" && error !== null && "statusCode" in error
|
||||
? (error as { readonly statusCode?: unknown }).statusCode
|
||||
const statusCode = Predicate.isObject(error) && Predicate.hasProperty(error, "statusCode")
|
||||
? error.statusCode
|
||||
: undefined;
|
||||
return status === 429 || statusCode === 429
|
||||
? TooManyRequestsError.make({ message: "Rate limit exceeded" })
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue