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
Bug Description
Get request with empty object as data does nothing on IOS simulator.
The promise never resolved, and no error thrown.
To Reproduce
I tried to send GET request using axios, using axios.request(options) method.
Here's the look of my options object
{
data: {},
...
}
As can be seen, there's data with empty object.
If i don't remove that data, then axios just doesn't do anything.
There's no error, nor the promise ever resolved.
I haven't tried this on actual IOS device though.
Here's the wrapper function i use to make the request
async_request(request){letoptions={// `url` is the server URL that will be used for the requesturl: request.url,// `method` is the request method to be used when making the requestmethod: request.method ? request.method : "get",// default// `baseURL` will be prepended to `url` unless `url` is absolute. It can be// convenient to set `baseURL` for an instance of axios to pass relative URLs to// methods of that instance.baseURL: this.BASE_URL,// baseURL: !identity ? loginServer : identityServer ,// `headers` are custom headers to be sent//headers: null,// `params` are the URL parameters to be sent with the request Must be a plain// object or a URLSearchParams object// params: null,// `data` is the data to be sent as the request body Only applicable for request// methods 'PUT', 'POST', and 'PATCH' When no `transformRequest` is set, must be// of one of the following types:// - string, plain object, ArrayBuffer, ArrayBufferView, URLSearchParams// - Browser only: FormData, File, Blob// - Node only: Stream, Buffer//data: null,// `timeout` specifies the number of milliseconds before the request times out.// If the request takes longer than `timeout`, the request will be aborted.//timeout: 1000,// `withCredentials` indicates whether or not cross-site Access-Control requests// should be made using credentials// withCredentials: false, // default// `responseType` indicates the type of data that the server will respond with// options are 'arraybuffer', 'blob', 'document', 'json', 'text', 'stream'// responseType: request.responseType ? request.responseType : 'json', // default// `validateStatus` defines whether to resolve or reject the promise for a given// HTTP response status code. If `validateStatus` returns `true` (or is set to// `null` or `undefined`), the promise will be resolved; otherwise, the promise// will be rejected.// validateStatus: function (status) {// return status >= 200 && status < 400; // default// },cancelToken: newCancelToken(function(cancel){// console.log("cancel",cancel)})};lettoken=awaitAsyncStorage.getItem(STORAGE.TOKEN_EXTRA);if(request.auth){//if basic authoptions["auth"]=request.auth;}if(token){letparseToken=awaitJSON.parse(token);letAuthorization="Bearer "+parseToken;options["headers"]={Authorization: Authorization};}// console.log(request.contentType)if(request.contentType){if(request.contentType===contentType.URLENCODED){options["headers"]={"Content-Type": "application/x-www-form-urlencoded"};}}if(request.params){options["params"]=request.params;}if(!isEmpty(request.data)){options["data"]=request.data;}// console.log(options);letres=axios.request(options);returnres.then(response=>{returnresponse.data;}).catch(error=>{// console.tron.log(error);if(error.response){// The request was made and the server responded with a status code// that falls out of the range of 2xx// console.log(error.response.data);console.log(error.response.status);console.log(error.response.headers);const{ status }=error.response;if(status>=200&&status<=400){// let message = error.response.data.error || error.response.data.messages || error.response.data.Messageletmessage=error.response.data.messages;// console.tron.log('error.response');// console.tron.log(error.response.data);throwmessage;}else{// let message = error.response.data;// console.tron.log(error);letmessage="Server Error";console.log("message",message);throwmessage;}// return error.response.data}elseif(error.request){// The request was made but no response was received// `error.request` is an instance of XMLHttpRequest in the browser and an instance of// http.ClientRequest in node.jsconsole.log("error.request",error.request);letmessage="Server Error";// throw error.requestthrowmessage;}else{// Something happened in setting up the request that triggered an Errorconsole.log("Error",error.message);throwerror.message;}});}
Notice that i need to check if request.data is empty in order to not include an empty object into data
Expected behavior
Axios should resolve the promise or at least rise an error.
Environment:
I'm using Expo to develop native mobile app.
Here's my package.json
Bug Description
Get request with empty object as data does nothing on IOS simulator.
The promise never resolved, and no error thrown.
To Reproduce
I tried to send GET request using axios, using
axios.request(options)
method.Here's the look of my
options
objectAs can be seen, there's
data
with empty object.If i don't remove that
data
, then axios just doesn't do anything.There's no error, nor the promise ever resolved.
I haven't tried this on actual IOS device though.
Here's the wrapper function i use to make the request
Notice that i need to check if
request.data
is empty in order to not include an empty object intodata
Expected behavior
Axios should resolve the promise or at least rise an error.
Environment:
I'm using Expo to develop native mobile app.
Here's my
package.json
The text was updated successfully, but these errors were encountered: