Skip to content

Commit

Permalink
feat: Handle 204 No Content responses and improve JSON parsing logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mamertofabian committed Jan 22, 2025
1 parent fe7efc6 commit bb80ee1
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/services/BaseGitHubService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ export abstract class BaseGitHubService {
throw apiError;
}

return await response.json();
// Return null for 204 No Content responses
if (response.status === 204) {
return null;
}

// Only try to parse JSON if there's actual content
const contentLength = response.headers.get('content-length');
const hasContent = contentLength === null || parseInt(contentLength) > 0;

if (hasContent) {
return await response.json();
}

return null;
}
}

0 comments on commit bb80ee1

Please sign in to comment.