Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | 16x 16x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 16x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 16x | export const ERROR = { BACKEND: { NOT_FOUND: "BACKEND::NOT_FOUND", RATE_LIMIT: "BACKEND::RATE_LIMIT", BAD_REQUEST: "BACKEND::BAD_REQUEST", UNAUTHORIZED: "BACKEND::UNAUTHORIZED", SERVER_ERROR: "BACKEND::SERVER_ERROR", UNKNOWN: "BACKEND::UNKNOWN" }, COMMON: { API_KEY_UNAVAILABLE: "COMMON::API_KEY_INVALID", UNKNOWN: "SDK::UNKNOWN" } } export const PREDEFINED_ERROR_REGISTRY = { [ERROR.BACKEND.NOT_FOUND]: { message: "🔍 We searched everywhere but couldn't find what you're looking for.", description: "The requested resource is missing.", possibleFix: "Verify the URL or resource identifier." }, [ERROR.BACKEND.BAD_REQUEST]: { message: "🚫 Bad Request. The request was malformed or incorrect.", description: null, possibleFix: "Please check your request format and parameters." }, [ERROR.BACKEND.UNAUTHORIZED]: { message: "🔑 Access Denied.", description: "You do not have the necessary credentials.", possibleFix: "Ensure your API key is correct and has the required permissions." }, [ERROR.BACKEND.SERVER_ERROR]: { message: "💥 Oops! Something went wrong on our end.", description: null, possibleFix: "Please try again later. If the issue persists, contact support." }, [ERROR.BACKEND.RATE_LIMIT]: { message: "⏱️ Slow down! You're moving too fast.", description: "You have exceeded the rate limit for requests.", possibleFix: "Please wait a bit before trying your request again." }, [ERROR.COMMON.API_KEY_UNAVAILABLE]: { message: "🔑 API Key Missing or Invalid.", description: "The API key provided is missing or incorrect.", possibleFix: "Ensure that your API key is passed to Client or set in your environment variables." }, UNKNOWN: { message: "❓ An unknown error occurred.", description: null, possibleFix: "Contact our support team with the error details for further assistance." }, [ERROR.BACKEND.UNKNOWN]: { message: "❓ An unknown error occurred.", description: null, possibleFix: "Contact our support team with the error details for further assistance." } } class ComposioError extends Error { constructor(public errCode: string, public message: string, public description?: string, public possibleFix?: string,originalError?:any) { super(message); this.name = 'ComposioError'; this.errCode = errCode; this.description = description; this.possibleFix = possibleFix; let detailedMessage = `Error Code: ${errCode}\nMessage: ${message}\n`; if (description) detailedMessage += `Description: ${description}\n`; if (possibleFix) detailedMessage += `Suggested Fix: ${possibleFix}\n`; Object.defineProperty(this, 'errCode', { enumerable: false }); Object.defineProperty(this, 'message', { enumerable: false }); Object.defineProperty(this, 'description', { enumerable: false }); Object.defineProperty(this, 'possibleFix', { enumerable: false }); this.stack = `${this.name}:${detailedMessage}Stack Trace: \n ${ originalError?.stack}`; } } // Composio Error Generator export class CEG { static handleError(axiosError: any,) { let errorDetails: { message: string; description: string | null; possibleFix: string; } = PREDEFINED_ERROR_REGISTRY.UNKNOWN as any; let errorKey = ERROR.COMMON.UNKNOWN; if (axiosError.response) { const { status } = axiosError.response; switch (status) { case 400: errorKey = ERROR.BACKEND.BAD_REQUEST; break; case 404: errorKey = ERROR.BACKEND.NOT_FOUND; break; case 429: errorKey = ERROR.BACKEND.RATE_LIMIT; break; case 401: errorKey = ERROR.BACKEND.UNAUTHORIZED; break; case 500: errorKey = ERROR.BACKEND.SERVER_ERROR; break; default: errorKey = ERROR.BACKEND.UNKNOWN; break; } if (errorKey !== ERROR.BACKEND.UNKNOWN) { errorDetails = PREDEFINED_ERROR_REGISTRY[errorKey]; }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(", ")}` } } elseE{ const description = axiosError.response.data.message || axiosError.response.data.error || axiosError.message; errorDetails = { message: axiosError.message, description: description, possibleFix: "Please check the network connection, request parameters, and ensure the API endpoint is correct." } } } let axiosDataMessage = axiosError.response?.data?.message || axiosError.message; const status = axiosError.response?.status || axiosError.status || axiosError.code || 'unknown'; 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}` : ''; const errorDescription = `❌ ${ifObjectStringify(errorDetails.description || axiosDataMessage) || "No additional information available."} ${urlAndStatus}`; throw new ComposioError( errorKey as string, errorDetails.message, errorDescription, errorDetails.possibleFix || "Please check the network connection and the request parameters.", axiosError ); } static throwCustomError(messageCode: string, { message, type, subtype, description, possibleFix }: { type?: string; subtype?: string; message?: string; description?: string; possibleFix?: string; }): never { const finalErrorCode = !!messageCode ? messageCode : `${type}::${subtype}`; const errorDetails = PREDEFINED_ERROR_REGISTRY[finalErrorCode] || PREDEFINED_ERROR_REGISTRY.UNKNOWN; const finalMessage = message || errorDetails.message; const finalDescription = description || errorDetails.description || undefined; const finalPossibleFix = possibleFix || errorDetails.possibleFix; throw new ComposioError(finalErrorCode, finalMessage, finalDescription, finalPossibleFix); } } export const ifObjectStringify = (obj: any) => { return typeof obj === 'object' ? JSON.stringify(obj) : obj; } |