feat: enhance logging for proxy testing errors by henrybarreto · Pull Request #1790 · EvolutionAPI/evolution-api · GitHub
Skip to content

feat: enhance logging for proxy testing errors#1790

Merged
DavidsonGomes merged 1 commit intoEvolutionAPI:developfrom
henrybarreto:feat/improve-test-proxy-error
Aug 7, 2025
Merged

feat: enhance logging for proxy testing errors#1790
DavidsonGomes merged 1 commit intoEvolutionAPI:developfrom
henrybarreto:feat/improve-test-proxy-error

Conversation

@henrybarreto
Copy link
Copy Markdown
Contributor

@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

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Aug 1, 2025

Copy link
Copy Markdown
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.

Comment thread src/api/controllers/proxy.controller.ts Outdated
logger.error('testProxy error: ' + error.message);
} else {
logger.error('testProxy error: ');
logger.error('testProxy error: unexpected error' + error);
Copy link
Copy Markdown
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
Copy link
Copy Markdown
Contributor Author

Copy link
Copy Markdown
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 marked this pull request as ready for review August 1, 2025 22:13
Copy link
Copy Markdown
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).
@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