question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

validateStatus doesn't work with auth

See original GitHub issue

Following is my code

try {
        const resToken = await axios({
            method: 'post',
            url: api.loginToken(),
            validateStatus: function(status) {
                return status < 500;
            },
            auth: {
                username: option.username,
                password: option.password
            }
        });
    } catch (error) {
        // some code here
    }

Even though the validateStatus is set to < 500, the following exception is called:

POST http://localhost:8000/api/login/token 404 (Not Found)

Can you help me please? Is this a bug or am I doing something wrong?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
Axnyffcommented, Jan 24, 2018

Oh sorry, I read your post too fast. It still seems to work with auth though.

I get an error logged to the console but my code never goes to the catch part because of the validateStatus

0reactions
jezikkcommented, Jan 24, 2018

@Axnyff Yes, it works. You need to use auth option as you mentioned.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to handle 401 (Authentication Error) in axios and react?
The above solution is great but does not work well with multiple failed request, in turn it calls getToken with the updated token...
Read more >
Understanding Axios GET requests - LogRocket Blog
Learn how to make GET requests in Axios with query parameters and API keys, plus concurrent and HEAD requests and error handling.
Read more >
Axios HTTP error handling in Express.js
An authentication error 401 or 403 should not occur in our outgoing authentication since we always send a valid JWT.
Read more >
Axios Cheat Sheet - Kapeli - Dash for macOS
`auth` indicates that HTTP Basic auth should be used, and supplies credentials. ... `validateStatus` defines whether to resolve or reject the promise for...
Read more >
Splunk AppInspect API endpoint reference
To obtain an authentication token, send a GET request to the ... GET request to the /v1/app/validate/status/{request_id} endpoint on appinspect.splunk.com.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found