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.

can't get errors after a post request

See original GitHub issue

I’dont know if this (#41) is fixed or not but i’ve this situation:

login(email = '', password = '') {
    let request = axios({
      url: api.session,
      method: 'post',
      data: {
        user: {
          email: email,
          password: password
        }
      },
      headers: {
        'Content-Type': 'application/json',
        'X-Requested-With': 'XMLHttpRequest'
      }
    })
    .catch(reason => {
      console.log(reason)
      return reason;
    })
    .then(function(response){
      console.log(response)
      return response;
    })
  }

but what i see is that the response arrives only if the status is 200 otherwise it doesn’t enter in catch and even in then it just stops.

this is what i see when i try to enter wrong credentials in my form:

XMLHttpRequest cannot load http://url/session. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8088' is therefore not allowed access. The response had HTTP status code 401.

EDIT:

this is my setup:

axios.defaults.headers.post['Content-Type'] = 'application/json';
axios.defaults.headers.post['Accept'] = 'application/json';
axios.defaults.transformRequest = [(data) => JSON.stringify(data.data)];

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
scerellicommented, Jan 27, 2016

It’s strange because i get this error only if user and pass are wrong otherwise if i type correct login data the promise works well because the server return 200

0reactions
peterkracikcommented, Apr 18, 2016

Hi I have the same problem. I’ve just switched from jquery ajax to axios, but I can’t make it works.

$.post(url, params, function() {…}); -> works great

axios({ method: ‘post’, url: url, data: params, headers: { ‘Content-Type’: ‘application/json’ } });

doesnt work. I get allways ‘method non allowed’ error, and I dont know why, but it sent as request method “OPTIONS” not “POST”. and I cant see my parameters either. Am I missing something? any solution? it needs to be POST and ‘Content-Type’: ‘application/json’.

thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot GET on POST request - Stack Overflow
You're seeing that error because you must be trying to access the url via the web browser, which sends the GET request.
Read more >
How to Fix Request Method 'POST' Not Supported - Hyperping
The Request Method' POST' Not Supported' is an HTTP response status. The error prompt shows that a request to access your website has...
Read more >
List of HTTP status codes - Wikipedia
This is a list of Hypertext Transfer Protocol (HTTP) response status codes. Status codes are issued by a server in response to a...
Read more >
Twitter API Response Codes & Error Support
Different error codes indicate different reasons for an error. The Twitter API attempts to return appropriate HTTP status codes for every request.
Read more >
Error Messages | Maps JavaScript API - Google Developers
An error has occurred that doesn't fit into the other categories on this page. This could be caused by a temporary problem. Please...
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