Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update backend error #1089

Merged
merged 3 commits into from
Dec 26, 2024

Conversation

himanshu-dixit
Copy link
Collaborator

@himanshu-dixit himanshu-dixit commented Dec 25, 2024

Important

Improved error handling in the SDK with detailed messages, added session ID to context, and updated tests for new error formats.

  • Error Handling:
    • Updated getAPIErrorDetails() in formatter.ts to provide more detailed error messages and descriptions.
    • Replaced BE_STATUS_CODE_TO_SDK_ERROR_CODES with API_TO_SDK_ERROR_CODE in error.ts and constants.ts.
    • Enhanced error handling in handleAllError() and throwAPIError() in error.ts.
  • SDK Context:
    • Added sessionId to ComposioSDKContext in composioContext.ts.
  • Tests:
    • Removed console.log statements from base.toolset.spec.ts.
    • Updated error handling tests in index.spec.ts to check for new error message formats.
  • Backend Client:
    • Added instance property to BackendClient in backendClient.ts for Axios instance management.

This description was created by Ellipsis for c19c9bf. It will automatically update as commits are pushed.

Copy link

vercel bot commented Dec 25, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
composio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 26, 2024 3:47am

@@ -86,5 +89,6 @@ export class BackendClient {
});

setAxiosClientConfig(axiosClient.instance);
this.instance = axiosClient.instance;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant assignment of this.instance. This is already assigned on line 39. Consider removing this duplicate assignment or add a comment explaining why it's needed twice.

const errorTypeFromBE = axiosError.response?.data?.error?.type;
const errorMessage = axiosError.response?.data?.error?.message;

const genericMessage = `${errorNameFromBE || predefinedError.message} ${errorTypeFromBE ? `- ${errorTypeFromBE}` : ""} on ${axiosError.config?.baseURL! + axiosError.config?.url!}`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding null/undefined checks for axiosError.config?.baseURL and axiosError.config?.url. While the optional chaining helps prevent crashes, concatenating with undefined values could lead to "undefined" appearing in the error message.

Copy link

github-actions bot commented Dec 25, 2024

This comment was generated by github-actions[bot]!

JS SDK Coverage Report

📊 Coverage report for JS SDK can be found at the following URL:
https://pub-92e668239ab84bfd80ee07d61e9d2f40.r2.dev/coverage-12499327649/coverage/index.html

📁 Test report folder can be found at the following URL:
https://pub-92e668239ab84bfd80ee07d61e9d2f40.r2.dev/html-report-12499327649/html-report/report.html

expect(e.description).toBe("Not found");
expect(e.errorId).toBeDefined();
expect(e.name).toBe("ComposioError");
expect(e.possibleFix).toBe(e.possibleFix);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test assertion expect(e.possibleFix).toBe(e.possibleFix) is comparing a value with itself, which will always pass. This should probably be comparing against an expected value instead.


try {
await client.apps.list();
const apps = await client.apps.list();
console.log(apps);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The console.log(apps) statement should be removed as it's not needed for the test and could clutter test output.

expect(error.name).toBe("ComposioError");
expect(error.possibleFix).toBe(errorInfo.possibleFix);
if (e instanceof ComposioError) {
console.log(e);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove console.log(e) from the test case. Debug logs should not be committed to the test suite.

@shreysingla11
Copy link
Collaborator

Code Review Summary

Overall Assessment

The changes improve error handling by better aligning with backend error responses and adding session tracking. The code quality is generally good, but there are a few areas that need attention.

Strengths

  • ✅ Improved error response structure with type, name, and message fields
  • ✅ Added session tracking for better error context
  • ✅ Better alignment with backend error format
  • ✅ Enhanced test coverage for error scenarios

Areas for Improvement

  1. Code Quality Issues:

    • Duplicate instance assignment in BackendClient
    • Potential undefined values in error message formatting
    • Debug console.log statements in test cases
    • Self-referential test assertion that doesn't provide value
  2. Suggestions:

    • Add null checks for URL components in error messages
    • Remove debug logging from test cases
    • Fix the self-referential test assertion
    • Consider adding JSDoc comments for new error types
    • Add validation for required error fields

Rating: 7/10

Good improvements to error handling, but needs cleanup of debug code and stronger validation.

@himanshu-dixit himanshu-dixit changed the title Ft update backend error feat: update backend error Dec 26, 2024
@himanshu-dixit himanshu-dixit marked this pull request as ready for review December 26, 2024 03:54
@himanshu-dixit himanshu-dixit merged commit 4e77538 into ft-update-backend-type Dec 26, 2024
14 checks passed
@himanshu-dixit himanshu-dixit deleted the ft-update-backend-error branch December 26, 2024 03:54
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good to me! Reviewed everything up to c19c9bf in 36 seconds

More details
  • Looked at 374 lines of code in 8 files
  • Skipped 0 files when reviewing.
  • Skipped posting 4 drafted comments based on config settings.
1. js/src/sdk/index.spec.ts:77
  • Draft comment:
      expect(error.message).toContain("InvalidRequestError");
  • Reason this comment was not posted:
    Comment looked like it was already resolved.
2. js/src/sdk/index.spec.ts:78
  • Draft comment:
      expect(error.message).toContain("InvalidRequestError");
  • Reason this comment was not posted:
    Marked as duplicate.
3. js/src/sdk/index.spec.ts:121
  • Draft comment:
    mock.onGet("/api/v1/apps").reply(500, { detail: "Internal Server Error" });
  • Reason this comment was not posted:
    Comment was on unchanged code.
4. js/src/sdk/index.spec.ts:122
  • Draft comment:
      error: {
        type: "ServerError",
        name: "InternalServerError",
        message: "Internal Server Error",
      },
  • Reason this comment was not posted:
    Marked as duplicate.

Workflow ID: wflow_ATOOL19T6OMPQiNN


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants