@samitouri / QOSami-HFS / commits / d957c9bc

fix: unhandled error on router mapping #774

Massimo Melina committed Oct 14, 2024 at 23:52 UTC d957c9bc6b955190502f650d4d433ffe7b7cce25
3 files changed +7 -8
admin/src/InternetPage.ts
+1 -1
@@ -401,7 +401,7 @@ export default function InternetPage() {
401 dialogProps: { sx: { maxWidth: '20em' } },
402 })
403 if (res)
404 - await mapPort(Number(res), "Port forwarded")
404 + await mapPort(Number(res), "Port forwarded").catch(() => {})
405
406 function remove() {
407 closeDialog()
src/api.net.ts
+5 -6
@@ -1,8 +1,7 @@
1 // This file is part of HFS - Copyright 2021-2023, Massimo Melina <a@rejetto.com> - License https://www.gnu.org/licenses/gpl-3.0.txt
2
3 import { ApiError, ApiHandlers } from './apiMiddleware'
4 -import { HTTP_FAILED_DEPENDENCY, HTTP_SERVER_ERROR, HTTP_SERVICE_UNAVAILABLE, HTTP_PRECONDITION_FAILED, HTTP_NOT_FOUND
5 -} from './const'
4 +import { HTTP_FAILED_DEPENDENCY, HTTP_SERVER_ERROR, HTTP_SERVICE_UNAVAILABLE, HTTP_PRECONDITION_FAILED } from './const'
5 import _ from 'lodash'
6 import { getCertObject } from './listen'
7 import { getProjectInfo } from './github'
@@ -46,16 +45,16 @@ const apis: ApiHandlers = {
45 async map_port({ external, internal }) {
46 const { upnp, externalPort, internalPort } = await getNatInfo()
47 if (!upnp)
49 - return new ApiError(HTTP_SERVICE_UNAVAILABLE, 'upnp failed')
48 + return new ApiError(HTTP_SERVICE_UNAVAILABLE, "upnp failed")
49 if (!internalPort)
51 - return new ApiError(HTTP_FAILED_DEPENDENCY, 'no internal port')
50 + return new ApiError(HTTP_FAILED_DEPENDENCY, "no internal port")
51 if (externalPort)
52 try { await upnpClient.removeMapping({ public: { host: '', port: externalPort } }) }
54 - catch (e: any) { return new ApiError(HTTP_SERVER_ERROR, 'removeMapping failed: ' + String(e) ) }
53 + catch (e: any) { return new ApiError(HTTP_SERVER_ERROR, "removeMapping failed: " + String(e) ) }
54 if (external) // must use the object form of 'public' to work around a bug of the library
55 await upnpClient.createMapping({ private: internal || internalPort, public: { host: '', port: external }, description: 'hfs', ttl: 0 })
56 .catch(res => {
58 - throw new ApiError(res.errorCode, res.errorCode === 718 ? "Port not available" : res.errorDescription)
57 + throw new ApiError(res.errorCode || res.statusCode, res.errorCode === 718 ? "Port not available" : res.errorDescription || "unknown error")
58 })
59 return {}
60 },
src/nat.ts
+1 -1
@@ -1,7 +1,7 @@
1 import { proxy } from 'valtio'
2 import { Client } from 'nat-upnp-rejetto'
3 import { debounceAsync } from './debounceAsync'
4 -import { haveTimeout, HOUR, inCommon, ipForUrl, MINUTE, promiseBestEffort, repeat, try_, wantArray } from './cross'
4 +import { haveTimeout, HOUR, inCommon, ipForUrl, MINUTE, promiseBestEffort, repeat, wantArray } from './cross'
5 import { getProjectInfo } from './github'
6 import _ from 'lodash'
7 import { httpString } from './util-http'