Skip to content

Commit

Permalink
refactor(lens): use ValidationNotValid error
Browse files Browse the repository at this point in the history
  • Loading branch information
mmackz committed Jun 27, 2024
1 parent 945d659 commit 10957c4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
10 changes: 2 additions & 8 deletions packages/lens/src/Lens.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ValidationNotValid } from './errors'
import { hasAddressCollectedPost } from './validate'
import {
ActionType,
Expand Down Expand Up @@ -46,14 +47,7 @@ export const validateCollect = async (
return hasCollected
} catch (err) {
console.error('[lens-plugin] Error while validating collect action')
if (err instanceof Error) {
const error = new Error(err.message)
error.name = 'ValidationNotValid'
throw error
} else {
console.error(err)
throw new Error('Unknown error')
}
throw new ValidationNotValid(err instanceof Error ? err : String(err))
}
}

Expand Down
12 changes: 12 additions & 0 deletions packages/lens/src/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export class ValidationNotValid extends Error {
constructor(input: string | Error) {
if (input instanceof Error) {
super(input.message)
Object.assign(this, input)

this.name = 'ValidationNotValid'
} else {
super(input)
}
}
}

0 comments on commit 10957c4

Please sign in to comment.