Archived
1
0

app.ts: Fix createApp to log all http server errors

cc @code-asher
This commit is contained in:
Anmol Sethi
2021-01-14 09:49:23 -05:00
parent 8acb2aec11
commit d3074278ca
3 changed files with 27 additions and 14 deletions

View File

@ -1,7 +1,7 @@
import * as http from "http"
import { logger } from "@coder/logger"
import { ensureAddress } from "../src/node/app"
import * as nodeFetch from "node-fetch"
import * as util from "../src/common/util"
import { ensureAddress } from "../src/node/app"
export class HttpServer {
private hs = http.createServer()
@ -25,7 +25,7 @@ export class HttpServer {
rej(err)
} else {
// Promise resolved earlier so this is some other error.
logError("server error", err)
util.logError("http server error", err)
}
})
})
@ -54,12 +54,3 @@ export class HttpServer {
return nodeFetch.default(`${ensureAddress(this.hs)}${requestPath}`, opts)
}
}
export function logError(prefix: string, err: any): void {
if (err instanceof Error) {
logger.error(`${prefix}: ${err.message} ${err.stack}`)
} else {
logger.error(`${prefix}: ${err}`)
}
}