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) 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') {