Skip to content

Commit

Permalink
fix[gen2][fetchEntries] ENG-7327 ensure fetchEntries function throws …
Browse files Browse the repository at this point in the history
…an error when API fails (#3734)

## Description

`fetchEntries` does not throw error

**Jira Ticket**
https://builder-io.atlassian.net/browse/ENG-7327

closes #3696

**Loom**
https://www.loom.com/share/b911923b99dd479ba06829deb788ed8e

---------

Co-authored-by: Clyde Mendonca <clydemendonca@Clydes-MacBook-Pro.local>
Co-authored-by: Sami Jaber <me@sami.website>
  • Loading branch information
3 people authored Nov 19, 2024
1 parent bf9ccaa commit 78b8e5d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
14 changes: 14 additions & 0 deletions .changeset/odd-pandas-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'@builder.io/sdk-angular': major
'@builder.io/sdk-react-nextjs': major
'@builder.io/sdk-qwik': major
'@builder.io/sdk-react': major
'@builder.io/sdk-react-native': major
'@builder.io/sdk-solid': major
'@builder.io/sdk-svelte': major
'@builder.io/sdk-vue': major
---

Breaking Change 🧨: `fetchEntries` and `fetchOneEntry` calls will now throw any errors thrown by `fetch`, or any non-success response returned from the Builder API.

Previously, both functions would swallow all errors and return `null`.
19 changes: 7 additions & 12 deletions packages/sdks/src/functions/get-content/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,13 @@ export const _processContentResult = async (
* Returns a paginated array of entries that match the given options.
*/
export async function fetchEntries(options: GetContentOptions) {
try {
const url = generateContentUrl(options);
const content = await _fetchContent(options);

if (!checkContentHasResults(content)) {
logger.error('Error fetching data. ', { url, content, options });
return null;
}
const url = generateContentUrl(options);
const content = await _fetchContent(options);

return _processContentResult(options, content);
} catch (error) {
logger.error('Error fetching data. ', error);
return null;
if (!checkContentHasResults(content)) {
logger.error('Error fetching data. ', { url, content, options });
throw content;
}

return _processContentResult(options, content);
}

0 comments on commit 78b8e5d

Please sign in to comment.