fix(core)!: map tl errors to MtPeerNotFoundError
in resolvePeer
This commit is contained in:
parent
5528ec3afb
commit
ef15b846a9
1 changed files with 20 additions and 8 deletions
|
@ -64,10 +64,16 @@ export async function resolvePeer(
|
||||||
const fromStorage = await client.storage.peers.getByPhone(peerId)
|
const fromStorage = await client.storage.peers.getByPhone(peerId)
|
||||||
if (fromStorage) return fromStorage
|
if (fromStorage) return fromStorage
|
||||||
|
|
||||||
res = await client.call({
|
try {
|
||||||
_: 'contacts.resolvePhone',
|
res = await client.call({
|
||||||
phone: peerId,
|
_: 'contacts.resolvePhone',
|
||||||
})
|
phone: peerId,
|
||||||
|
})
|
||||||
|
} catch (e) {
|
||||||
|
if (tl.RpcError.is(e, 'PHONE_NOT_OCCUPIED')) {
|
||||||
|
throw new MtPeerNotFoundError(`Peer with phone number ${peerId} was not found`)
|
||||||
|
} else throw e
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// username
|
// username
|
||||||
if (!force) {
|
if (!force) {
|
||||||
|
@ -75,10 +81,16 @@ export async function resolvePeer(
|
||||||
if (fromStorage) return fromStorage
|
if (fromStorage) return fromStorage
|
||||||
}
|
}
|
||||||
|
|
||||||
res = await client.call({
|
try {
|
||||||
_: 'contacts.resolveUsername',
|
res = await client.call({
|
||||||
username: peerId,
|
_: 'contacts.resolveUsername',
|
||||||
})
|
username: peerId,
|
||||||
|
})
|
||||||
|
} catch (e) {
|
||||||
|
if (tl.RpcError.is(e, 'USERNAME_NOT_OCCUPIED')) {
|
||||||
|
throw new MtPeerNotFoundError(`Peer with username ${peerId} was not found`)
|
||||||
|
} else throw e
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res.peer._ === 'peerUser') {
|
if (res.peer._ === 'peerUser') {
|
||||||
|
|
Loading…
Reference in a new issue