File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
src/publish/confluence/api Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments