Skip to content

Commit

Permalink
fix: bubble up errors from api to frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
christianmat committed Nov 22, 2024
1 parent d1a9708 commit 066265e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/few-chairs-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'trench-js': patch
---

Bubble up errors from the backend to the frontend exception
11 changes: 9 additions & 2 deletions packages/trench-js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,12 @@ class Trench {
});

if (!response.ok) {
throw new Error('Failed to query events');
if (response.status === 400) {
const errorResponse = await response.json();
throw new Error(errorResponse.message);
}
throw new Error('Failed to get events');
}

return response.json();
}

Expand All @@ -168,6 +171,10 @@ class Trench {
});

if (!response.ok) {
if (response.status === 400) {
const errorResponse = await response.json();
throw new Error(errorResponse.message);
}
throw new Error('Failed to execute query');
}

Expand Down

0 comments on commit 066265e

Please sign in to comment.