Skip to content

Commit

Permalink
Merge branch 'master' into devin/1735478042-update-entity-id-and-exec…
Browse files Browse the repository at this point in the history
…ute-format
  • Loading branch information
abhishekpatil4 authored Jan 3, 2025
2 parents 385772e + b8532ee commit 99f1dcc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
2 changes: 2 additions & 0 deletions js/src/sdk/base.toolset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ export class ComposioToolSet {
// fetch connected account id
const connectedAccounts = await this.client.connectedAccounts.list({
user_uuid: entityId,
status: "ACTIVE",
showActiveOnly: true,
});
accountId = connectedAccounts?.items[0]?.id;
}
Expand Down
14 changes: 12 additions & 2 deletions js/src/sdk/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ describe("Basic SDK spec suite", () => {
type: "BadRequestError",
name: "InvalidRequestError",
message: "Invalid request for apps",
details: [
{
property: "triggerConfig",
children: [],
constraints: {
isObject: "triggerConfig must be an object",
},
},
],
});

const client = new Composio({ apiKey: COMPOSIO_API_KEY });
Expand All @@ -70,9 +79,10 @@ describe("Basic SDK spec suite", () => {
const error = e as ComposioError;
const errorCode = COMPOSIO_SDK_ERROR_CODES.BACKEND.BAD_REQUEST;
expect(error.errCode).toBe(errorCode);
expect(error.message).toContain("InvalidRequestError ");
expect(error.message).toContain("InvalidRequestError");
expect(error.description).toContain("Invalid request for apps");
expect(error.description).toContain(
`Validation Errors: {"property":"triggerConfig","children":[],"constraints":{"isObject":"triggerConfig must be an object"}}`
);
}

mock.reset();
Expand Down
15 changes: 14 additions & 1 deletion js/src/sdk/utils/errors/src/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface ErrorResponseData {
type: string;
name: string;
message: string;
details?: Record<string, unknown>[] | Record<string, unknown>;
}

interface ErrorDetails {
Expand Down Expand Up @@ -53,13 +54,25 @@ export const getAPIErrorDetails = (
}

switch (errorCode) {
case COMPOSIO_SDK_ERROR_CODES.BACKEND.BAD_REQUEST:
const validationErrors = axiosError.response?.data?.details;
const formattedErrors = Array.isArray(validationErrors)
? validationErrors.map((err) => JSON.stringify(err)).join(", ")
: JSON.stringify(validationErrors);

return {
message: genericMessage,
description: `Validation Errors: ${formattedErrors}`,
possibleFix:
"Please check the request parameters and ensure they are correct.",
metadata,
};
case COMPOSIO_SDK_ERROR_CODES.BACKEND.NOT_FOUND:
case COMPOSIO_SDK_ERROR_CODES.BACKEND.UNAUTHORIZED:
case COMPOSIO_SDK_ERROR_CODES.BACKEND.SERVER_ERROR:
case COMPOSIO_SDK_ERROR_CODES.BACKEND.SERVER_UNAVAILABLE:
case COMPOSIO_SDK_ERROR_CODES.BACKEND.RATE_LIMIT:
case COMPOSIO_SDK_ERROR_CODES.BACKEND.UNKNOWN:
case COMPOSIO_SDK_ERROR_CODES.BACKEND.BAD_REQUEST:
return {
message: genericMessage,
description: errorMessage || (predefinedError.description as string),
Expand Down

0 comments on commit 99f1dcc

Please sign in to comment.