Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | import { Data } from 'effect'; |
| 2 | import type { Cause } from 'effect'; |
| 3 | import type { ComposioError, ConfigurationError } from '@composio/client/effect'; |
| 4 | |
| 5 | type NoSuchElementError = Cause.NoSuchElementError; |
| 6 | |
| 7 | /** |
| 8 | * Error thrown when a client cannot be constructed from the current configuration. |
| 9 | */ |
| 10 | export class ComposioClientConfigurationError extends Data.TaggedError( |
| 11 | 'services/ComposioClientConfigurationError' |
| 12 | )<{ |
| 13 | readonly message: string; |
| 14 | readonly cause: unknown; |
| 15 | }> {} |
| 16 | |
| 17 | /** |
| 18 | * Error thrown when a HTTP response doesn't match the expected response schema. |
| 19 | */ |
| 20 | export class HttpDecodingError extends Data.TaggedError('services/HttpDecodingError')<{ |
| 21 | readonly cause?: unknown; |
| 22 | /** |
| 23 | * The request whose response failed, as the client names its operation |
| 24 | * (`toolRouter.session.search`). With it, the failure is reported like the |
| 25 | * client's own `DecodeError`: by operation, with an upgrade hint, never with |
| 26 | * the schema issues, which may quote the response. |
| 27 | */ |
| 28 | readonly operation?: string; |
| 29 | }> {} |
| 30 | |
| 31 | /** |
| 32 | * A failure of a request made through the Effect client: a non-success status, |
| 33 | * a transport failure, a timeout, or a response body that failed decoding. |
| 34 | * `ConfigurationError` is the one client error that is not a request failure. |
| 35 | */ |
| 36 | export type ClientApiError = Exclude<ComposioError, ConfigurationError>; |
| 37 | |
| 38 | /** |
| 39 | * The tags of {@link ClientApiError}, for `Effect.catchTag`. |
| 40 | */ |
| 41 | export const CLIENT_API_ERROR_TAGS = [ |
| 42 | '@composio/client/BadRequestError', |
| 43 | '@composio/client/AuthenticationError', |
| 44 | '@composio/client/PermissionDeniedError', |
| 45 | '@composio/client/NotFoundError', |
| 46 | '@composio/client/ConflictError', |
| 47 | '@composio/client/UnprocessableEntityError', |
| 48 | '@composio/client/RateLimitError', |
| 49 | '@composio/client/InternalServerError', |
| 50 | '@composio/client/APIError', |
| 51 | '@composio/client/APIConnectionError', |
| 52 | '@composio/client/APIConnectionTimeoutError', |
| 53 | '@composio/client/DecodeError', |
| 54 | ] as const satisfies ReadonlyArray<ClientApiError['_tag']>; |
| 55 | |
| 56 | export type ClientApiErrorTag = (typeof CLIENT_API_ERROR_TAGS)[number]; |
| 57 | |
| 58 | /** |
| 59 | * Every failure a client call can produce: the request itself, as the client's |
| 60 | * own tagged error, decoding a CLI-owned contract, or obtaining a client from |
| 61 | * the singleton. |
| 62 | */ |
| 63 | export type ClientError = |
| 64 | ComposioError | HttpDecodingError | ComposioClientConfigurationError | NoSuchElementError; |