Skip to content
Merged
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
13 changes: 11 additions & 2 deletions src/publish/confluence/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,19 @@ export class ConfluenceClient {
};
}

private handleResponse<T>(response: Response) {
private async handleResponse<T>(response: Response) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

In case anyone else looks at this: the change to async here changes the type of handleResponse. That means the handleResponse call sites change as well, but inspecting the code here shows that the only two call sites are already async, and call handleResponse in tail position. That means those calls do not need an additional await.

if (response.ok) {
if (response.body) {
return response.json() as unknown as T;
// Some Confluence API endpoints return successfull calls with no body while using content-type "application/json"
// example: https://developer.atlassian.com/cloud/confluence/rest/v1/api-group-content-restrictions/#api-wiki-rest-api-content-id-restriction-byoperation-operationkey-bygroupid-groupid-get
// To prevent JSON parsing errors we have to return null for empty bodies and only parse when there is content
let data = await response.text();

if (data === "") {
return null as unknown as T;
} else {
return JSON.parse(data) as unknown as T;
}
} else {
return response as unknown as T;
}
Expand Down
Loading