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

Fixed XHR error on put requests when the query params are long #2

Merged
merged 4 commits into from Sep 28, 2018
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/service/request.js
Expand Up @@ -46,17 +46,21 @@ module.exports = function(Api) {

this.httpConfig.headers = this.httpConfig.headers || {};

if( method === this.Methods.GET
&& (( this.httpConfig.url + '?' + JSON.stringify(params)).length > 1500
|| path === 'batch' )) {
this.httpConfig.method = this.Methods.POST;
params.method = this.Methods.GET;
this.httpConfig.data = this.serializer(params);
this.httpConfig.params = undefined;
this.httpConfig.headers['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
} else if(data) {
if(data) {
this.httpConfig.data = data;
this.httpConfig.headers['Content-Type'] = 'application/json;charset=utf-8';
} else if( method === this.Methods.GET && (( this.httpConfig.url + '?' + JSON.stringify(params)).length > 1500 || path === 'batch' )) {
this.httpConfig.method = this.Methods.POST;
params.method = this.Methods.GET;
this.httpConfig.data = this.serializer(params);
this.httpConfig.params = undefined;
this.httpConfig.headers['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
} else if (method === this.Methods.PUT && (this.httpConfig.url + '?' + JSON.stringify(params)).length > 1500 && !data) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need !data check here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No we don't

this.httpConfig.method = this.Methods.POST;
params.method = this.Methods.PUT;
this.httpConfig.data = this.serializer(params);
this.httpConfig.params = undefined;
this.httpConfig.headers['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
}

return this.http(this.httpConfig);
Expand Down