From 1842dea5b6a84ba77da37f492bd5b0f40c6ebac9 Mon Sep 17 00:00:00 2001 From: Himanshu Dixit Date: Wed, 27 Nov 2024 22:16:22 +0530 Subject: [PATCH 1/8] feat: add error message details --- js/src/sdk/utils/error.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/js/src/sdk/utils/error.ts b/js/src/sdk/utils/error.ts index b24a3ba87a..d58cd27a95 100644 --- a/js/src/sdk/utils/error.ts +++ b/js/src/sdk/utils/error.ts @@ -111,8 +111,14 @@ export class CEG { errorKey = ERROR.BACKEND.UNKNOWN; break; } - if (errorKey) { + if (errorKey !== ERROR.BACKEND.UNKNOWN) { errorDetails = PREDEFINED_ERROR_REGISTRY[errorKey]; + }else{ + errorDetails = { + message: axiosError.message, + description: axiosError.response.data.message || axiosError.response.data.error || axiosError.message, + possibleFix: "Please check the network connection, request parameters, and ensure the API endpoint is correct." + } } } From a582e6b3f9c376ca7edd1cb96dd4c02c2d761423 Mon Sep 17 00:00:00 2001 From: Himanshu Dixit Date: Wed, 27 Nov 2024 22:20:32 +0530 Subject: [PATCH 2/8] feat: update error --- js/src/sdk/utils/error.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/src/sdk/utils/error.ts b/js/src/sdk/utils/error.ts index d58cd27a95..c8bb3400c1 100644 --- a/js/src/sdk/utils/error.ts +++ b/js/src/sdk/utils/error.ts @@ -102,7 +102,7 @@ export class CEG { errorKey = ERROR.BACKEND.RATE_LIMIT; break; case 401: - errorKey = ERROR.COMMON.API_KEY_UNAVAILABLE; + errorKey = ERROR.BACKEND.UNAUTHORIZED; break; case 500: errorKey = ERROR.BACKEND.SERVER_ERROR; From 1989d3280fc13c3cc8b1b991a34466c8d4d1ec1e Mon Sep 17 00:00:00 2001 From: Himanshu Dixit Date: Thu, 28 Nov 2024 10:35:39 +0530 Subject: [PATCH 3/8] feat: x request id --- js/package.json | 3 ++- js/sample.ts | 10 ++++++++++ js/src/sdk/index.ts | 3 --- js/src/sdk/models/apps.ts | 4 ++++ js/src/sdk/utils/config.ts | 4 +++- js/src/sdk/utils/error.ts | 15 ++++++++------- 6 files changed, 27 insertions(+), 12 deletions(-) create mode 100644 js/sample.ts diff --git a/js/package.json b/js/package.json index 087fcacfb4..6f44c56f5a 100644 --- a/js/package.json +++ b/js/package.json @@ -12,7 +12,8 @@ "type-docs": "typedoc", "openapispec:generate": "npx @hey-api/openapi-ts", "run:cli": "ts-node src/cli/index.ts", - "run:sample": "ts-node sample.ts" + "run:sample": "ts-node sample.ts", + "eslint": "eslint src/**/*.ts" }, "bin": { "composio-js": "./lib/src/cli/index", diff --git a/js/sample.ts b/js/sample.ts new file mode 100644 index 0000000000..91b62dd253 --- /dev/null +++ b/js/sample.ts @@ -0,0 +1,10 @@ +import {Composio} from "./src/index" + +async function main() { + const composio = new Composio("u7ta9pbl3iz37qap6wdnk"); + + const apps = await composio.apps.list(); + // console.log(apps); +} + +main(); \ No newline at end of file diff --git a/js/src/sdk/index.ts b/js/src/sdk/index.ts index c2a57b0077..06e7d213de 100644 --- a/js/src/sdk/index.ts +++ b/js/src/sdk/index.ts @@ -12,10 +12,7 @@ import axios from 'axios'; import { getPackageJsonDir } from './utils/projectUtils'; import { isNewerVersion } from './utils/other'; import { getClientBaseConfig } from './utils/config'; -import chalk from 'chalk'; import { CEG, ERROR } from './utils/error'; -import { ActionProxyRequestConfigDTO } from './client'; -import apiClient from '../sdk/client/client'; import { GetConnectorInfoResDTO } from './client'; import logger from '../utils/logger'; diff --git a/js/src/sdk/models/apps.ts b/js/src/sdk/models/apps.ts index b594acb8f8..6626c6f981 100644 --- a/js/src/sdk/models/apps.ts +++ b/js/src/sdk/models/apps.ts @@ -40,6 +40,10 @@ export class Apps { async list(){ try { const {data} = await apiClient.apps.getApps(); + + const a = 5; + // @ts-ignore + return a.b.c; return data?.items || []; } catch (error) { throw CEG.handleError(error); diff --git a/js/src/sdk/utils/config.ts b/js/src/sdk/utils/config.ts index 897ee9cfe5..a67da30176 100644 --- a/js/src/sdk/utils/config.ts +++ b/js/src/sdk/utils/config.ts @@ -27,7 +27,9 @@ export const setAxiosClientConfig = (axiosClientInstance: AxiosInstance) => { axiosClientInstance.interceptors.response.use( (response) => { const responseSize = Math.round(JSON.stringify(response.data).length / 1024); - logger.debug(`API Res [${response.status}] ${response.config.method?.toUpperCase()} ${response.config.url} ${responseSize} KB`); + logger.debug(`API Res [${response.status}] ${response.config.method?.toUpperCase()} ${response.config.url} ${responseSize} KB`, { + 'x-request-id': response.headers['x-request-id'] + }); return response; }, (error) => { diff --git a/js/src/sdk/utils/error.ts b/js/src/sdk/utils/error.ts index c8bb3400c1..11396814ab 100644 --- a/js/src/sdk/utils/error.ts +++ b/js/src/sdk/utils/error.ts @@ -1,4 +1,3 @@ - export const ERROR = { BACKEND: { NOT_FOUND: "BACKEND::NOT_FOUND", @@ -52,7 +51,7 @@ export const PREDEFINED_ERROR_REGISTRY = { }, [ERROR.BACKEND.UNKNOWN]: { message: "❓ An unknown error occurred.", - description: "The error is not recognized by our system.", + description: null, possibleFix: "Contact our support team with the error details for further assistance." } } @@ -65,7 +64,6 @@ class ComposioError extends Error { this.possibleFix = possibleFix; let detailedMessage = `Error Code: ${errCode}\nMessage: ${message}\n`; - let detailedDescription = description; if (description) detailedMessage += `Description: ${description}\n`; if (possibleFix) detailedMessage += `Suggested Fix: ${possibleFix}\n`; @@ -75,8 +73,7 @@ class ComposioError extends Error { Object.defineProperty(this, 'description', { enumerable: false }); Object.defineProperty(this, 'possibleFix', { enumerable: false }); - - this.stack = `${this.name}: ${detailedMessage}Stack Trace:\n${(new Error()).stack}`; + this.stack = `${this.name}:${detailedMessage}Stack Trace: \n ${ originalError?.stack}`; } } @@ -84,7 +81,11 @@ class ComposioError extends Error { // Composio Error Generator export class CEG { static handleError(axiosError: any,) { - let errorDetails = PREDEFINED_ERROR_REGISTRY.UNKNOWN; + let errorDetails: { + message: string; + description: string | null; + possibleFix: string; + } = PREDEFINED_ERROR_REGISTRY.UNKNOWN as any; let errorKey = ERROR.COMMON.UNKNOWN; @@ -157,7 +158,7 @@ export class CEG { const errorDetails = PREDEFINED_ERROR_REGISTRY[finalErrorCode] || PREDEFINED_ERROR_REGISTRY.UNKNOWN; - throw new ComposioError(messageCode, message || errorDetails.message, description || errorDetails.description, possibleFix || errorDetails.possibleFix); + throw new ComposioError(messageCode, message || errorDetails.message, description || errorDetails.description || undefined, possibleFix || errorDetails.possibleFix); } } From aa8f2be900f43af7eaa8a415bde18e74ff2ac917 Mon Sep 17 00:00:00 2001 From: Himanshu Dixit Date: Thu, 28 Nov 2024 13:31:55 +0530 Subject: [PATCH 4/8] fix: change errors --- js/src/sdk/models/apps.ts | 4 ---- js/src/sdk/utils/error.ts | 22 +++++++++++++++------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/js/src/sdk/models/apps.ts b/js/src/sdk/models/apps.ts index 6626c6f981..b594acb8f8 100644 --- a/js/src/sdk/models/apps.ts +++ b/js/src/sdk/models/apps.ts @@ -40,10 +40,6 @@ export class Apps { async list(){ try { const {data} = await apiClient.apps.getApps(); - - const a = 5; - // @ts-ignore - return a.b.c; return data?.items || []; } catch (error) { throw CEG.handleError(error); diff --git a/js/src/sdk/utils/error.ts b/js/src/sdk/utils/error.ts index 11396814ab..878ec0e819 100644 --- a/js/src/sdk/utils/error.ts +++ b/js/src/sdk/utils/error.ts @@ -20,8 +20,8 @@ export const PREDEFINED_ERROR_REGISTRY = { possibleFix: "Verify the URL or resource identifier." }, [ERROR.BACKEND.BAD_REQUEST]: { - message: "🚫 That didn't work as expected.", - description: "Your request was malformed or incorrect.", + message: "🚫 Bad Request. The request was malformed or incorrect.", + description: null, possibleFix: "Please check your request format and parameters." }, [ERROR.BACKEND.UNAUTHORIZED]: { @@ -31,7 +31,7 @@ export const PREDEFINED_ERROR_REGISTRY = { }, [ERROR.BACKEND.SERVER_ERROR]: { message: "💥 Oops! Something went wrong on our end.", - description: "An unexpected error occurred on the server.", + description: null, possibleFix: "Please try again later. If the issue persists, contact support." }, [ERROR.BACKEND.RATE_LIMIT]: { @@ -46,7 +46,7 @@ export const PREDEFINED_ERROR_REGISTRY = { }, UNKNOWN: { message: "❓ An unknown error occurred.", - description: "The error is not recognized by our system.", + description: null, possibleFix: "Contact our support team with the error details for further assistance." }, [ERROR.BACKEND.UNKNOWN]: { @@ -114,7 +114,15 @@ export class CEG { } if (errorKey !== ERROR.BACKEND.UNKNOWN) { errorDetails = PREDEFINED_ERROR_REGISTRY[errorKey]; - }else{ + }if(errorKey === ERROR.BACKEND.BAD_REQUEST){ + const axiosErrorMessage = axiosError.response.data.message; + const errors = axiosError.response.data.errors; + errorDetails = { + ...PREDEFINED_ERROR_REGISTRY.UNKNOWN, + description: `${axiosErrorMessage} ${errors.map((error:any) => JSON.stringify(error)).join(", ")}` + } + } + else{ errorDetails = { message: axiosError.message, description: axiosError.response.data.message || axiosError.response.data.error || axiosError.message, @@ -129,11 +137,11 @@ export class CEG { const request_id = axiosError.response?.headers?.["x-request-id"]; const urlAndStatus = axiosError.config?.url ? ` got 📊 ${status} response from URL🔗: ${axiosError.config.url}, request_id: ${request_id}` : ''; - axiosDataMessage = `❌ ${ifObjectStringify(axiosDataMessage) || errorDetails.description || "No additional information available."} ${urlAndStatus}`; + const errorDescription = `❌ ${ifObjectStringify(errorDetails.description || axiosDataMessage) || "No additional information available."} ${urlAndStatus}`; throw new ComposioError( errorKey as string, errorDetails.message, - axiosDataMessage || errorDetails.description || "No additional information available.", + errorDescription, errorDetails.possibleFix || "Please check the network connection and the request parameters.", axiosError ); From d3bf70d28f584fac4fdf07753a3af039c748529b Mon Sep 17 00:00:00 2001 From: Apoorv Taneja Date: Thu, 28 Nov 2024 13:37:16 +0530 Subject: [PATCH 5/8] Delete js/sample.ts --- js/sample.ts | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 js/sample.ts diff --git a/js/sample.ts b/js/sample.ts deleted file mode 100644 index 91b62dd253..0000000000 --- a/js/sample.ts +++ /dev/null @@ -1,10 +0,0 @@ -import {Composio} from "./src/index" - -async function main() { - const composio = new Composio("u7ta9pbl3iz37qap6wdnk"); - - const apps = await composio.apps.list(); - // console.log(apps); -} - -main(); \ No newline at end of file From 08def0a4bd740a4494bd1bb693f99a355b7184cc Mon Sep 17 00:00:00 2001 From: Himanshu Dixit Date: Thu, 28 Nov 2024 13:39:43 +0530 Subject: [PATCH 6/8] feat: error --- js/src/sdk/utils/error.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/js/src/sdk/utils/error.ts b/js/src/sdk/utils/error.ts index 878ec0e819..b56c48614e 100644 --- a/js/src/sdk/utils/error.ts +++ b/js/src/sdk/utils/error.ts @@ -123,9 +123,10 @@ export class CEG { } } else{ + const description = axiosError.response.data.message || axiosError.response.data.error || axiosError.message; errorDetails = { message: axiosError.message, - description: axiosError.response.data.message || axiosError.response.data.error || axiosError.message, + description: description, possibleFix: "Please check the network connection, request parameters, and ensure the API endpoint is correct." } } From 0fe528503ea2fd67fdd028b18c753b25b16f7887 Mon Sep 17 00:00:00 2001 From: Himanshu Dixit Date: Thu, 28 Nov 2024 13:45:32 +0530 Subject: [PATCH 7/8] feat: error code --- js/src/sdk/utils/error.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/js/src/sdk/utils/error.ts b/js/src/sdk/utils/error.ts index b56c48614e..1e37c65300 100644 --- a/js/src/sdk/utils/error.ts +++ b/js/src/sdk/utils/error.ts @@ -164,10 +164,13 @@ export class CEG { }): never { const finalErrorCode = !!messageCode ? messageCode : `${type}::${subtype}`; - const errorDetails = PREDEFINED_ERROR_REGISTRY[finalErrorCode] || PREDEFINED_ERROR_REGISTRY.UNKNOWN; - throw new ComposioError(messageCode, message || errorDetails.message, description || errorDetails.description || undefined, possibleFix || errorDetails.possibleFix); + const finalMessage = message || errorDetails.message; + const finalDescription = description || errorDetails.description || undefined; + const finalPossibleFix = possibleFix || errorDetails.possibleFix; + + throw new ComposioError(finalErrorCode, finalMessage, finalDescription, finalPossibleFix); } } From 7e38dc696c2e7ebaa1dbde2902a87f9599b1a5f8 Mon Sep 17 00:00:00 2001 From: Himanshu Dixit Date: Thu, 28 Nov 2024 14:34:10 +0530 Subject: [PATCH 8/8] feat: bump version --- js/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/package.json b/js/package.json index 6f44c56f5a..f912d976ad 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "composio-core", - "version": "0.2.9-10-1", + "version": "0.3.0-beta.1", "description": "", "main": "lib/src/index.js", "scripts": { @@ -83,4 +83,4 @@ "publishConfig": { "access": "public" } -} \ No newline at end of file +}