fix(core)!: map tl errors to MtPeerNotFoundError in resolvePeer

This commit is contained in:
alina 🌸 2024-05-30 18:21:40 +03:00
parent 5528ec3afb
commit ef15b846a9
Signed by: teidesu
SSH key fingerprint: SHA256:uNeCpw6aTSU4aIObXLvHfLkDa82HWH9EiOj9AXOIRpI

View file

@ -64,10 +64,16 @@ export async function resolvePeer(
const fromStorage = await client.storage.peers.getByPhone(peerId)
if (fromStorage) return fromStorage
try {
res = await client.call({
_: '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 {
// username
if (!force) {
@ -75,10 +81,16 @@ export async function resolvePeer(
if (fromStorage) return fromStorage
}
try {
res = await client.call({
_: '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') {