Skip to content

Commit

Permalink
fix(server): forward server status and headers
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Nov 25, 2024
1 parent 3232011 commit 6b12099
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,18 @@ class SatoriServer extends Service<SatoriServer.Config> {
koa.status = 404
return
}
const result = await bot.internal[name](...koa.request.body)
koa.body = result
koa.status = 200
try {
const result = await bot.internal[name](...koa.request.body)
koa.body = result
koa.status = 200
} catch (error) {
if (!ctx.http.isError(error) || !error.response) throw error
koa.status = error.response.status
koa.body = error.response.data
for (const [key, value] of error.response.headers) {
koa.set(key, value)
}
}
})

ctx.server.get(path + '/v1/proxy/:url(.+)', async (koa) => {
Expand Down

0 comments on commit 6b12099

Please sign in to comment.