Skip to content

Commit

Permalink
Don't create unnecessary error objects (#1908)
Browse files Browse the repository at this point in the history
* Don't create unnecessary error objects

* add changeset

---------

Co-authored-by: dholms <dtholmgren@gmail.com>
  • Loading branch information
gaearon and dholms authored Nov 30, 2023
1 parent 6da8182 commit 3c0ef38
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/brave-swans-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@atproto/syntax': patch
---

prevent unnecessary throw/catch on uri syntax
10 changes: 5 additions & 5 deletions packages/syntax/src/aturi_validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ export const ensureValidAtUri = (uri: string) => {
}

try {
ensureValidHandle(parts[2])
} catch {
try {
if (parts[2].startsWith('did:')) {
ensureValidDid(parts[2])
} catch {
throw new Error('ATURI authority must be a valid handle or DID')
} else {
ensureValidHandle(parts[2])
}
} catch {
throw new Error('ATURI authority must be a valid handle or DID')
}

if (parts.length >= 4) {
Expand Down

0 comments on commit 3c0ef38

Please sign in to comment.