Skip to content

Commit

Permalink
More error handling cleanup within connectWallet
Browse files Browse the repository at this point in the history
  • Loading branch information
ccali11 committed Jun 20, 2023
1 parent 2647163 commit 9bba739
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
3 changes: 1 addition & 2 deletions apps/web/src/composables/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ export default function useUsers () {
user.value = userAccount
return { error, message, data: userAccount }
} catch (error) {
console.log('Error in addAccount in wallet.ts :>> ', error)
return { error: true, message: 'Error adding account', data: null }
throw new Error(error.message || 'Error adding account')
}
}

Expand Down
17 changes: 8 additions & 9 deletions apps/web/src/composables/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,14 @@ export default function useWallet() {
ownerAddress: user?.value?.address.toLowerCase() as string,
walletProvider: selectedProvider.value
}
const addAccountResponse = await addAccount(account)
if (!addAccountResponse?.error) {
const getUserResponse = await getUser()
setUser(getUserResponse.data)
setPrimaryAddress(user?.value?.address as string)
} else {
console.error('There was an error adding the account :>> ', addAccountResponse.message)
throw new Error(addAccountResponse.message)
}
const { error: addAccountError, message: addAccountMessage } = await addAccount(account)
if (addAccountError) throw new Error(addAccountMessage || 'There was an error adding the account')

const { error: getUserError, message: getUserMessage, data: getUserData } = await getUser()
if (getUserError) throw new Error(getUserMessage || 'There was an error getting the user')

setUser(getUserData)
setPrimaryAddress(user?.value?.address as string)
}
}
await setUserAccountBalances()
Expand Down
2 changes: 0 additions & 2 deletions services/users/src/routes/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const { addAccount, getUser, updateUserAddress, removeAccount } = useDB()

router.get('/', verifySession(), async (req: SessionRequest, res: express.Response) => {
try {
console.log('go to / in user.ts')
const address = req.session?.getUserId().toLowerCase() as string
const user = await getUser(address)
const message = user ? 'User found' : 'User not found'
Expand All @@ -21,7 +20,6 @@ router.get('/', verifySession(), async (req: SessionRequest, res: express.Respon
user
})
} catch (err) {
console.log('Error in / route of user.ts :>> ', err)
res.status(500)
res.json({
message: 'Error getting user',
Expand Down

0 comments on commit 9bba739

Please sign in to comment.