-
Notifications
You must be signed in to change notification settings - Fork 4
feat #655: implements an error handling system with custom errors #657
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a6ecff3
693e08e
9cc8a9f
3ce8694
23271e8
59548f7
9ad4a2f
e94ea47
be65dcb
dcd254c
deede94
d550cda
26b9738
60ceebe
0952c4e
f04b042
2b661f1
51089fd
f2733e8
583946e
6ea7a41
efcaec5
f0364fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
|
|
||
| import { GiftExchange } from '@/app/types/giftExchange'; | ||
| import { SupabaseClient } from '@supabase/supabase-js'; | ||
| import { SupabaseError } from '@/lib/errors/CustomErrors'; | ||
|
|
||
| /** | ||
| * Fetches all gift exchanges in the database. | ||
|
|
@@ -17,11 +18,15 @@ export const fetchGiftExchanges = async ({ | |
| const { data, error } = await supabase.from('gift_exchanges').select('*'); | ||
|
|
||
| if (error) { | ||
| throw new Error(error.message); | ||
| throw new SupabaseError( | ||
| 'Failed to fetch gift exchanges', | ||
| error.code, | ||
| error, | ||
| ); | ||
| } | ||
|
|
||
| if (data.length === 0) { | ||
| throw new Error('No gift exchanges found.'); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. Are we forcing a status error instead of using the one given from the error object?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is because the error object that's returned is a https://docs.postgrest.org/en/v12/references/errors.html#errors-from-postgrest |
||
| throw new SupabaseError('No gift exchanges found', 500, error); | ||
| } | ||
|
|
||
| return data; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this forcing a 500 error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes because when declaring a new custom error, the

statusCodeis required as a parameter. Since this only tests that an error is thrown, I just added any code.