(res: ServerResponse, status: number, statusMessage: string, body: unknown)
| 35 | } |
| 36 | |
| 37 | function writeJson(res: ServerResponse, status: number, statusMessage: string, body: unknown): void { |
| 38 | const json = Buffer.from(JSON.stringify(body), 'utf-8'); |
| 39 | res.writeHead(status, statusMessage, { |
| 40 | 'content-type': 'application/json', |
| 41 | 'content-length': json.length |
| 42 | }); |
| 43 | res.write(json); |
| 44 | res.end(); |
| 45 | } |
| 46 | |
| 47 | function writeError(res: ServerResponse, status: number, statusMessage: string, e?: Error): void { |
| 48 | writeJson(res, status, statusMessage, e ? { message: e.message, stack: e.stack } : { message: statusMessage }); |
no test coverage detected