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

remove axios dependency #503

Closed
wants to merge 2 commits into from
Closed

Conversation

matt-fidd
Copy link
Contributor

Reported in discord, this is causing an issue because it's not in the package.json

To avoid adding a large dependency I've rolled our own here, referencing https://github.com/axios/axios/blob/5d54d22321b3c3d29c5dff5e8086cd9db7e2d101/lib/helpers/isAxiosError.js#L12

@actual-github-bot actual-github-bot bot changed the title remove axios dependency [WIP] remove axios dependency Nov 14, 2024
@matt-fidd matt-fidd changed the title [WIP] remove axios dependency remove axios dependency Nov 14, 2024
@matt-fidd matt-fidd assigned matt-fidd and unassigned matt-fidd Nov 14, 2024
Copy link
Contributor

@MikesGlitch MikesGlitch left a comment

Choose a reason for hiding this comment

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

Not sure why we need to check if it's an axios error - I'm assuming that'll never be the case here since we don't use axios.

However, this will definately fix the error reported so happy to go with this.

Copy link
Contributor

coderabbitai bot commented Nov 14, 2024

Walkthrough

The pull request introduces changes to the error handling logic within the /transactions endpoint of the GoCardless application. The primary modification involves altering the method of checking for Axios errors; instead of using the isAxiosError function, the code now directly accesses the isAxiosError property on the error object. This adjustment aims to simplify the detection of Axios-related errors. The existing error handling structure remains unchanged, with specific cases still defined for various error types, including RequisitionNotLinked, AccountNotLinkedToRequisition, RateLimitError, and GenericGoCardlessError. Each case constructs a response object containing relevant error details to be sent back to the client. The overall control flow and logic for handling successful responses are preserved, ensuring that the application continues to function correctly based on the outcomes of service calls. No changes were made to the declarations of exported or public entities.

Possibly related PRs

Suggested reviewers

  • MatissJanis

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
src/app-gocardless/app-gocardless.js (2)

Line range hint 239-249: Implementation still depends on Axios

The changes appear inconsistent with the PR objective of removing the Axios dependency. While the code has been modified to check the isAxiosError property directly, it still:

  1. Relies on Axios-specific error properties (error.isAxiosError)
  2. Uses Axios response patterns (error.response?.data)

Consider implementing a custom error handler that doesn't depend on Axios patterns. Here's a suggested approach:

-case error.isAxiosError:
+case error.name === 'NetworkError':
   console.log(
     'Something went wrong',
-    inspect(error.response?.data || error, { depth: null }),
+    inspect(error.details || error, { depth: null }),
   );
   sendErrorResponse({
     error_type: 'SYNC_ERROR',
-    error_code: 'NORDIGEN_ERROR',
+    error_code: 'NETWORK_ERROR',
   });
   break;

Line range hint 239-262: Consider refactoring error handling for better maintainability

The current error handling structure has some duplication and inconsistencies in logging. Consider extracting the error mapping logic to a separate function for better maintainability.

Here's a suggested refactoring:

const ERROR_MAPPINGS = {
  NetworkError: {
    error_type: 'SYNC_ERROR',
    error_code: 'NETWORK_ERROR'
  },
  GenericGoCardlessError: {
    error_type: 'SYNC_ERROR',
    error_code: 'NORDIGEN_ERROR'
  },
  // ... other mappings
};

function logError(error, context = '') {
  console.log(
    `Something went wrong${context ? ` - ${context}` : ''}`,
    inspect(error, { depth: null })
  );
}

function handleTransactionError(error) {
  const errorType = error.constructor.name;
  const errorMapping = ERROR_MAPPINGS[errorType] || {
    error_type: 'UNKNOWN',
    error_code: 'UNKNOWN',
    reason: 'Something went wrong'
  };
  
  logError(error, errorType);
  return { ...errorMapping, details: error.details };
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b1bf7ee and a5a14bd.

⛔ Files ignored due to path filters (1)
  • upcoming-release-notes/503.md is excluded by !**/*.md
📒 Files selected for processing (1)
  • src/app-gocardless/app-gocardless.js (1 hunks)
🔇 Additional comments (1)
src/app-gocardless/app-gocardless.js (1)

Line range hint 239-249: Verify the impact of removing Axios

Since the PR aims to remove the Axios dependency, we should verify all potential uses of Axios in the codebase to ensure complete removal.

#!/bin/bash
# Search for any remaining Axios-related code
echo "Searching for Axios imports..."
rg -i "axios" --type js

echo "Searching for Axios error handling patterns..."
rg "isAxiosError|error\.response\?\.data" --type js

echo "Checking package.json for axios dependency..."
if [ -f "package.json" ]; then
    jq '.dependencies.axios, .devDependencies.axios' package.json
fi

@matt-fidd
Copy link
Contributor Author

Closing, root cause of the error is not what we thought

@matt-fidd matt-fidd closed this Nov 14, 2024
@matt-fidd matt-fidd deleted the remove-axios branch December 11, 2024 23:12
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