Skip to content

Commit 4eb8abf

Browse files
authored
Merge pull request #13415 from m1no/bugfix/issue-13414
Fix to meet api specification for empty bodies
2 parents cfc3637 + 94b7e13 commit 4eb8abf

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/publish/confluence/api/index.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,19 @@ export class ConfluenceClient {
381381
};
382382
}
383383

384-
private handleResponse<T>(response: Response) {
384+
private async handleResponse<T>(response: Response) {
385385
if (response.ok) {
386386
if (response.body) {
387-
return response.json() as unknown as T;
387+
// Some Confluence API endpoints return successfull calls with no body while using content-type "application/json"
388+
// 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
389+
// To prevent JSON parsing errors we have to return null for empty bodies and only parse when there is content
390+
let data = await response.text();
391+
392+
if (data === "") {
393+
return null as unknown as T;
394+
} else {
395+
return JSON.parse(data) as unknown as T;
396+
}
388397
} else {
389398
return response as unknown as T;
390399
}

0 commit comments

Comments
 (0)