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

Shorter error report #6724

Open
thewh1teagle opened this issue Dec 2, 2024 · 1 comment
Open

Shorter error report #6724

thewh1teagle opened this issue Dec 2, 2024 · 1 comment

Comments

@thewh1teagle
Copy link

Is your feature request related to a problem? Please describe.

Currently when there's some http error I get maybe 1000 lines of error in stderr from axios.
Why do I need to see every possible object configured in that http request by default?
This way it's too much verbose and I can't understand anything from the log.

Describe the solution you'd like

Disable verbose by default. also, is there a workaround meanwhile?

Describe alternatives you've considered

No response

Additional context/Screenshots

No response

@thewh1teagle
Copy link
Author

import axios from "axios";

axios.interceptors.response.use(
    resp => resp,
    err => {
      let msg = 'Unknown error';
      const url = err.config?.url || 'Unknown URL';
  
      if (err.response) {
        // Get first 200 characters from the response data
        try {
          const dataSnippet = JSON.stringify(err.response.data).slice(0, 200);
          msg = `[Error] URL: ${url} - Status: ${err.response.status} - Data: ${dataSnippet}`;
        } catch {
          msg = `[Error] URL: ${url} - Status: ${err.response.status} - Data: failed to deserialize`;
        }
      } else if (err.request) {
        msg = `[Error] URL: ${url} - No response from server`;
      } else {
        msg = `[Error] URL: ${url} - Setup issue: ${err.message}`;
      }
      return Promise.reject(new Error(msg));
    }
);

export default axios

Anyone looking for relief from long errors in Axios will find this quite useful. I would enable similar error report by default.

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

No branches or pull requests

1 participant