Skip to content

Commit 4c52eee

Browse files
authored
feat: fix duplicate uploaded key (#1431)
* put appropriate err message for duplicate uploaded key * put appropriate err message for duplicate uploaded key
1 parent 12ae3ef commit 4c52eee

File tree

1 file changed

+11
-2
lines changed
  • packages/wallet/backend/src/walletAddressKeys

1 file changed

+11
-2
lines changed

packages/wallet/backend/src/walletAddressKeys/service.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import { v4 as uuid } from 'uuid'
55
import { WalletAddressKeys } from './model'
66
import { WalletAddressService } from '@/walletAddress/service'
77
import { WalletAddress } from '@/walletAddress/model'
8-
import { NotFound } from '@shared/backend'
8+
import { BadRequest, NotFound } from '@shared/backend'
9+
import { UniqueViolationError } from 'objection'
910

1011
export type KeyResponse = {
1112
privateKey: string
@@ -91,7 +92,15 @@ export class WalletAddressKeyService implements IWalletAddressKeyService {
9192
walletAddressId
9293
}
9394

94-
await WalletAddressKeys.query().insert(key)
95+
try {
96+
await WalletAddressKeys.query().insert(key)
97+
} catch (e) {
98+
if (e instanceof UniqueViolationError)
99+
throw new BadRequest(
100+
'Same key already uploaded. Please upload a unique one.'
101+
)
102+
else throw e
103+
}
95104
}
96105

97106
async registerKey({

0 commit comments

Comments
 (0)