You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
The problem
The error
TypeError: Cannot read property 'replace' of undefined
is thrown whencontentType
is undefined. Seems to be caused by 49358caThis 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#86Steps 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:Mocker-api will fail with the error
TypeError: Cannot read property 'replace' of undefined
becausecontentType
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.The text was updated successfully, but these errors were encountered: