Skip to content

Commit

Permalink
Show response error in typeahead example
Browse files Browse the repository at this point in the history
  • Loading branch information
fe9lix committed Oct 13, 2021
1 parent 45a4b9a commit cc41527
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions examples/api-examples/src/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ export function usePackageSearch(query: string | undefined): {
try {
const url = `https://api.npms.io/v2/search?q=${query ?? ""}`;
const response = await fetch(url);

if (!response.ok) {
setError(response.statusText);
return;
}

const json = await response.json();

if (!cancel) {
Expand Down

0 comments on commit cc41527

Please sign in to comment.