Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clients/imodels-client-management/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"extends": "./node_modules/@itwin/imodels-client-common-config/.eslintrc.json"
},
"dependencies": {
"axios": "^1.0.0"
"axios": "1.1.0"
},
"devDependencies": {
"@itwin/imodels-client-common-config": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export class AxiosRestClient implements RestClient {

constructor(parseErrorFunc: ParseErrorFunc) {
this._parseErrorFunc = parseErrorFunc;
delete axios.defaults.headers.post["Content-Type"];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please add a comment explaining why we are doing this. Also does this solution require to pin axios to exact version 1.1.0?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There is a problem with transpiling axios on 1.1.3, here's an issue for further information:
axios/axios#5011
it should would work if all axios import statements would be changed to require('axios') but since it's a bug inside axios i'm not sure if it is worth to do it rather than just to change version and wait for new version

delete axios.defaults.headers.patch["Content-Type"];
}

public sendGetRequest<TResponse>(params: HttpGetRequestParams & { responseType: ContentType.Json }): Promise<TResponse>;
Expand All @@ -43,7 +45,7 @@ export class AxiosRestClient implements RestClient {
headers: params.headers
};

return this.executeRequest(async () => axios.post(params.url, params.body.content ?? {}, requestConfig));
return this.executeRequest(async () => axios.post(params.url, params.body.content, requestConfig));
}

public async sendPutRequest<TResponse>(params: HttpRequestWithBinaryBodyParams): Promise<TResponse> {
Expand All @@ -59,7 +61,7 @@ export class AxiosRestClient implements RestClient {
headers: params.headers
};

return this.executeRequest(async () => axios.patch(params.url, params.body.content ?? {}, requestConfig));
return this.executeRequest(async () => axios.patch(params.url, params.body.content, requestConfig));
}

public async sendDeleteRequest<TResponse>(params: HttpRequestParams): Promise<TResponse> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export class OperationsBase<TOptions extends OperationsBaseOptions> {
}
}

private async formHeaders(params: CommonRequestParams & { preferReturn?: PreferReturn, contentType?: ContentType}): Promise<Dictionary<string>> {
private async formHeaders(params: CommonRequestParams & { preferReturn?: PreferReturn, contentType?: ContentType, body?: object }): Promise<Dictionary<string>> {
const headers: Dictionary<string> = {};
const authorizationInfo = await params.authorization();
headers[Constants.headers.authorization] = `${authorizationInfo.scheme} ${authorizationInfo.token}`;
Expand All @@ -128,7 +128,7 @@ export class OperationsBase<TOptions extends OperationsBaseOptions> {
if (params.preferReturn)
headers[Constants.headers.prefer] = `return=${params.preferReturn}`;

if (params.contentType)
if (params.contentType && params.body !== undefined)
headers[Constants.headers.contentType] = params.contentType;

this.addOrUpdateHeaders(headers, this._options.headers);
Expand Down
Loading