refactor(#56): Improve how the dex updating is handled and the error messaging around it

This commit is contained in:
Josh Creek
2026-01-10 12:07:05 +00:00
parent 845cc1c739
commit b1b6e63b6f
11 changed files with 700 additions and 107 deletions
+16 -3
View File
@@ -70,7 +70,10 @@ class PokedexRepository {
if (error) {
console.error('Error creating pokedex:', error);
throw new Error(`Failed to create pokedex: ${error.message}`);
// Preserve the Supabase error code so the API layer can map to a user-friendly response.
throw Object.assign(new Error(`Failed to create pokedex: ${error.message}`), {
code: error.code
});
}
if (!result) {
@@ -91,12 +94,22 @@ class PokedexRepository {
.select()
.single();
if (error || !result) return null;
if (error) {
console.error('Error updating pokedex:', error);
throw Object.assign(new Error(`Failed to update pokedex: ${error.message}`), {
code: error.code
});
}
if (!result) return null;
return this.transform(result);
}
async delete(id: string): Promise<void> {
const { error } = await this.supabase.from('pokedexes').delete().eq('id', id).eq('userId', this.userId);
const { error } = await this.supabase
.from('pokedexes')
.delete()
.eq('id', id)
.eq('userId', this.userId);
if (error) {
console.error('Error deleting pokedex:', error);