fix: admin/home: errors not handled when pasting bad zip links with right-click
Massimo Melina committed
Mar 29, 2024 at 14:16 UTC
0cba96f490bdc223a54ed6b95950939ed9244bd5
3 files changed
+6
-2
src/adminApis.ts
+3
-1
@@ -72,7 +72,9 @@ export const adminApis: ApiHandlers = {
72
}
73
},
74
set_config_text: ({ text }) => configFile.save(text, { reparse: true }),
75
- update: ({ tag }) => update(tag).catch(e => e.cause?.statusCode ? new ApiError(e.cause?.statusCode) : e),
75
+ update: ({ tag }) => update(tag).catch(e => {
76
+ throw e.cause?.statusCode ? new ApiError(e.cause?.statusCode) : e
77
+ }),
78
async check_update() {
79
return { options: await getUpdates() }
80
},
src/apiMiddleware.ts
+2
@@ -51,6 +51,8 @@ export function apiMiddleware(apis: ApiHandlers) : Koa.Middleware {
51
}
52
}
53
catch(e) {
54
+ if (typeof e === 'string') // message meant to be transmitted
55
+ return send(HTTP_BAD_REQUEST, e)
56
if (typeof e === 'number')
57
e = new ApiError(e)
58
res = e
src/update.ts
+1
-1
@@ -121,8 +121,8 @@ export async function update(tagOrUrl: string='') {
121
setTimeout(() => process.exit()) // give time to return (and caller to complete, eg: rest api to reply)
122
}
123
catch (e: any) {
124
- console.error(e?.message || String(e))
124
pluginsWatcher.unpause()
125
+ throw e?.message || String(e)
126
}
127
}
128