Skip to content

Commit

Permalink
refactor: Handle more errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ci010 committed Dec 25, 2023
1 parent a16561c commit a0c0640
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
1 change: 1 addition & 0 deletions xmcl-runtime/peer/PeerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ export class PeerService extends StatefulService<PeerState> implements IPeerServ
if (ip && port) {
const state = await natService.getNatState()
await mapLocalPort(natService, state.localIp, privatePort, Number(port), this).catch((e) => {
if (e.name === 'Error') { e.name = 'MapNatError' }
this.error(e)
})
}
Expand Down
4 changes: 1 addition & 3 deletions xmcl-runtime/peer/mapAndGetPortCanidate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,13 @@ export async function mapLocalPort(natService: NatService, ip: string, priv: num
if (err.detail?.UPnPError && err.detail?.UPnPError.errorCode === 501) {
// Table is full
const candidates = getUnmapCandidates(currentMappings, mappings)
console.log(candidates)
for (const c of candidates) {
await natService.unmap(c).catch(() => {})
}
await Promise.all(mappings.map(n => natService.map(n)))
} else if (err.detail.UPnPError && err.detail.UPnPError.errorCode === 718) {
} else if (err.detail?.UPnPError && err.detail.UPnPError.errorCode === 718) {
// Conflict
const candidates = getUnmapCandidates(currentMappings, mappings)
console.log(candidates)
for (const c of candidates) {
await natService.unmap(c).catch(() => {})
}
Expand Down

0 comments on commit a0c0640

Please sign in to comment.