Skip to content

Commit

Permalink
Improve error reporting to server consumers
Browse files Browse the repository at this point in the history
Previously we emmitted error codes without any error data. Instead,
actually transmit received errors to the Braekhus server consumer.
  • Loading branch information
nbrahms committed Sep 20, 2024
1 parent c9fb6d0 commit 883344b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
JSONRPCServer,
JSONRPCServerAndClient,
} from "json-rpc-2.0";
import { isArray, omit } from "lodash";
import { omit } from "lodash";
import { Logger } from "pino";
import WebSocket from "ws";

Expand Down
1 change: 1 addition & 0 deletions log/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const createLogger = <T extends LoggerOptions>(
): Logger<T> => {
const logger = pinoLogger({
...options,
name: `braekhus.${options.name}`,
level: process.env.LOG_LEVEL || "info",
serializers: {
error: serializeError,
Expand Down
8 changes: 4 additions & 4 deletions server/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const httpProxyApp = (
const matches = PATH_REGEXP.exec(req.path);
logger.debug({ matches }, "path matches");
if (matches === null || matches.length !== 3) {
res.sendStatus(400);
res.status(404).json({ error: "Invalid path format" });
}

const clientId = (matches as string[])[1];
Expand Down Expand Up @@ -78,7 +78,7 @@ export const httpProxyApp = (
// See See https://nodejs.org/api/stream.html#readablepipedestination-options
stream.pipe(res);
} else {
res.status(response.status).send(response.data);
res.status(response.status).json(response.data);
}
} catch (error: any) {
logger.error({ error, spammy: true }, "Error handling request");
Expand All @@ -89,9 +89,9 @@ export const httpProxyApp = (
(error.message.startsWith("timeout") &&
error.message.endsWith("exceeded"))
) {
res.sendStatus(504);
res.status(504).json({ error });
} else {
res.sendStatus(502);
res.status(502).json({ error });
}
}
});
Expand Down

0 comments on commit 883344b

Please sign in to comment.