Skip to content

feat: enhance logging for proxy testing errors #1790

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

Conversation

henrybarreto
Copy link

@henrybarreto henrybarreto commented Aug 1, 2025

This commit improves the logging in the testProxy method of the ProxyController class. Now, when an Axios error occurs, the specific error message will be logged if available. For unexpected errors, the error object is included for better insight.

For reference, see the "message" field in the Axios documentation: Axios Error Handling.

Summary by Sourcery

Enhance logging in ProxyController.testProxy to include explicit info/warn messages for success and IP unchanged scenarios and to log detailed Axios and unexpected errors

Enhancements:

  • Log info when proxy connection succeeds and warn if the origin IP remains unchanged
  • Include Axios error messages in the logs and append unexpected error objects for non-Axios errors

Copy link
Contributor

sourcery-ai bot commented Aug 1, 2025

Reviewer's Guide

This PR refactors the testProxy method to improve observability by logging the outcome of the proxy test (success or unchanged origin IP) and enhancing error handling to capture specific Axios error messages and unexpected errors.

Class diagram for updated ProxyController.testProxy method

classDiagram
    class ProxyController {
        +testProxy(proxy)
    }
    class logger {
        +info(message)
        +warn(message)
        +error(message)
    }
    class axios {
        +isAxiosError(error)
    }
    ProxyController --> logger : uses
    ProxyController --> axios : uses
Loading

Flow diagram for enhanced logging in testProxy method

flowchart TD
    A[Start testProxy] --> B[Make request with Axios]
    B -->|Success| C{Is response.data different from serverIp.data?}
    C -- Yes --> D[Log info: proxy connection successful]
    C -- No --> E[Log warn: proxy connection doesn't change the origin IP]
    D --> F[Return result]
    E --> F
    B -->|Error| G{Is AxiosError?}
    G -- Yes --> H[Log error: axios error + error.message]
    G -- No --> I[Log error: unexpected error + error]
    H --> J[Return false]
    I --> J
Loading

File-Level Changes

Change Details Files
Report testProxy outcome with distinct logs
  • Capture comparison result in a local variable
  • Log info on successful proxy connection
  • Log warning when origin IP remains unchanged
src/api/controllers/proxy.controller.ts
Streamline and enrich error logging
  • Combine Axios error branch to log error.message
  • Remove prior branching on response data
  • Log unexpected errors with the full error object
src/api/controllers/proxy.controller.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @henrybarreto - I've reviewed your changes - here's some feedback:

  • In the unexpected error branch, pass the error object as a separate argument to logger.error (e.g. logger.error('testProxy error: unexpected error', error)) or JSON.stringify it to capture the full stack trace instead of string concatenation.
  • Add a separator (e.g. ': ') before concatenating the error to improve log readability (currently it produces 'unexpected error[object Object]').
  • The extra error.message check in the second branch is redundant since all AxiosError instances include a message—consider simplifying that condition to just axios.isAxiosError(error).
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In the unexpected error branch, pass the error object as a separate argument to logger.error (e.g. logger.error('testProxy error: unexpected error', error)) or JSON.stringify it to capture the full stack trace instead of string concatenation.
- Add a separator (e.g. ': ') before concatenating the error to improve log readability (currently it produces 'unexpected error[object Object]').
- The extra error.message check in the second branch is redundant since all AxiosError instances include a message—consider simplifying that condition to just axios.isAxiosError(error).

## Individual Comments

### Comment 1
<location> `src/api/controllers/proxy.controller.ts:63` </location>
<code_context>
+        logger.error('testProxy error: ' + error.message);
       } else {
-        logger.error('testProxy error: ');
+        logger.error('testProxy error: unexpected error' + error);
       }
       return false;
</code_context>

<issue_to_address>
String concatenation with an Error object may not yield useful output.

Instead of concatenating the error object, pass it as a separate argument to logger.error to retain full error details.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

} else {
logger.error('testProxy error: ');
logger.error('testProxy error: unexpected error' + error);
Copy link
Contributor

Choose a reason for hiding this comment

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

issue: String concatenation with an Error object may not yield useful output.

Instead of concatenating the error object, pass it as a separate argument to logger.error to retain full error details.

@henrybarreto henrybarreto force-pushed the feat/improve-test-proxy-error branch from 4b20bcd to a7600fe Compare August 1, 2025 16:00
@henrybarreto
Copy link
Author

@sourcery-ai review

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @henrybarreto - I've reviewed your changes and found some issues that need to be addressed.

  • Consider logging the error.stack alongside the message to provide better debugging context when tracing issues.
  • Rather than JSON.stringify(error), pass the error object directly to the logger or use util.inspect to capture non-enumerable properties and avoid missing details.
  • Verify that logging error.response.data won’t expose any sensitive information—scrub or truncate if necessary before writing to the logs.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider logging the error.stack alongside the message to provide better debugging context when tracing issues.
- Rather than JSON.stringify(error), pass the error object directly to the logger or use util.inspect to capture non-enumerable properties and avoid missing details.
- Verify that logging error.response.data won’t expose any sensitive information—scrub or truncate if necessary before writing to the logs.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@henrybarreto henrybarreto marked this pull request as draft August 1, 2025 18:51
@henrybarreto henrybarreto force-pushed the feat/improve-test-proxy-error branch 2 times, most recently from 650f37a to ca4f0cd Compare August 1, 2025 22:13
@henrybarreto henrybarreto marked this pull request as ready for review August 1, 2025 22:13
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @henrybarreto - I've reviewed your changes - here's some feedback:

  • Consider including error.response.data alongside error.message when logging Axios errors so you don’t lose potentially important server response details.
  • For unexpected errors, pass the actual error object into logger.error rather than concatenating it to a string to preserve the full stack trace and context.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider including error.response.data alongside error.message when logging Axios errors so you don’t lose potentially important server response details.
- For unexpected errors, pass the actual error object into logger.error rather than concatenating it to a string to preserve the full stack trace and context.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@DavidsonGomes DavidsonGomes changed the base branch from main to develop August 4, 2025 21:51
This commit improves the logging in the testProxy method of the
ProxyController class. Now, when an Axios error occurs, the specific
error message will be logged if available. For unexpected errors, the
error object is included for better insight.

For reference, see the "message" field in the Axios documentation:
[Axios Error Handling](https://axios-http.com/docs/handling_errors).
@henrybarreto henrybarreto force-pushed the feat/improve-test-proxy-error branch from ca4f0cd to ab9e0ed Compare August 5, 2025 10:08
@DavidsonGomes DavidsonGomes merged commit 40ce6b5 into EvolutionAPI:develop Aug 7, 2025
1 check passed
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