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

TypeError: Cannot read property 'replace' of undefined #51

Closed
arloduff opened this issue Aug 10, 2019 · 2 comments
Closed

TypeError: Cannot read property 'replace' of undefined #51

arloduff opened this issue Aug 10, 2019 · 2 comments

Comments

@arloduff
Copy link
Contributor

arloduff commented Aug 10, 2019

The problem

The error TypeError: Cannot read property 'replace' of undefined is thrown when contentType is undefined. Seems to be caused by 49358ca

This is problematic for users such as myself, who use Axios, which deliberately strips out a Content-Type header from any request which is not sending data, even if one is provided. See axios/axios#86

Steps to reproduce

Send a request to your mock-api which does not have a Content-Type header. Using Axios, you can send something similar to:

this.axios.get(url), {
  headers: {
    'Content-Type': 'application/json',
    Accept: 'application/json'
  },
  params: {
    // Your parameters here
  }
}).then(result => result.data)

Mocker-api will fail with the error TypeError: Cannot read property 'replace' of undefined because contentType will come out as undefined, even though it was provided.

I understand you may argue that Axios should not be stripping out the Content-Type from the request; however, it's still a good practice for this codebase to check for one before calling replace on a variable which may be undefined.

@jaywcjlove
Copy link
Owner

@arloduff Upgrade + [email protected]

@arloduff
Copy link
Contributor Author

Thanks @jaywcjlove !

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

2 participants