Skip to content

Commit

Permalink
fix: throw error and handle in catch block
Browse files Browse the repository at this point in the history
  • Loading branch information
MuckT committed Jun 30, 2023
1 parent 9f5fb08 commit 103e6c1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/nfts/saga.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ describe('Given Nfts saga', () => {
])
.put(
fetchNftsFailed({
error: 'Could not parse NFTs',
error:
'invalid json response body at reason: Unexpected token i in JSON at position 0',
})
)
.run()
Expand Down
8 changes: 5 additions & 3 deletions src/nfts/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ export function* handleFetchNfts() {
Accept: 'application/json',
},
})
if (!response.ok) yield put(fetchNftsFailed({ error: 'Could not fetch NFTs' }))
if (!response.ok) {
throw new Error('Could not fetch NFTs')
}
const { result } = yield call([response, 'json'])
yield put(fetchNftsCompleted(result))
} catch (error) {
Logger.error(TAG, 'Could not parse NFTs response', error)
yield put(fetchNftsFailed({ error: 'Could not parse NFTs' }))
Logger.error(TAG, '@handleFetchNfts', error)
yield put(fetchNftsFailed({ error: error.message }))
}
}

Expand Down

0 comments on commit 103e6c1

Please sign in to comment.