Skip to content

Commit

Permalink
fix(route): 🐛 properly show error when updating an item fails
Browse files Browse the repository at this point in the history
  • Loading branch information
djdembeck committed Aug 9, 2024
1 parent 8ba0043 commit c457327
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/helpers/routes/GenericShowHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ import PaprAudibleBookHelper from '#helpers/database/papr/audible/PaprAudibleBoo
import PaprAudibleChapterHelper from '#helpers/database/papr/audible/PaprAudibleChapterHelper'
import RedisHelper from '#helpers/database/redis/RedisHelper'
import SharedHelper from '#helpers/utils/shared'
import { ErrorMessageDataType, ErrorMessageMissingOriginal } from '#static/messages'
import {
ErrorMessageDataType,
ErrorMessageMissingOriginal,
ErrorMessageUpdate
} from '#static/messages'

export default class GenericShowHelper {
asin: string
Expand Down Expand Up @@ -189,7 +193,7 @@ export default class GenericShowHelper {
(await this.createOrUpdateData()
.then((data) => data)
.catch((err) => {
console.log(`Error updating ${this.type}`, err)
throw new Error(err)
})) || dataOnError

// 3. Return the data
Expand Down Expand Up @@ -221,7 +225,12 @@ export default class GenericShowHelper {
if (this.originalData) {
// 3.
if (this.options.update === '1') {
return this.updateActions()
// Try to update the data, if it fails, throw an error
try {
return await this.updateActions()
} catch {
throw new Error(ErrorMessageUpdate(this.asin, this.type))
}
}

// 2.
Expand Down

0 comments on commit c457327

Please sign in to comment.