fix: unhandled error on router mapping #774
Massimo Melina committed
Oct 14, 2024 at 23:52 UTC
3f6140d2ff2aa3993fca874341dc4a2dd93429c2
2 files changed
+6
-7
admin/src/InternetPage.ts
+1
-1
@@ -393,7 +393,7 @@ export default function InternetPage() {
393
dialogProps: { sx: { maxWidth: '20em' } },
394
})
395
if (res)
396
- await mapPort(Number(res), "Port forwarded")
396
+ await mapPort(Number(res), "Port forwarded").catch(() => {})
397
398
function remove() {
399
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
},