Skip to content

Commit

Permalink
Improve error reporting to server consumers (#29)
Browse files Browse the repository at this point in the history
* Improve error reporting to server consumers

Previously we emmitted error codes without any error data. Instead,
actually transmit received errors to the Braekhus server consumer.

* Also: update test ports to avoid conflicts in the local system
  • Loading branch information
nbrahms authored Sep 20, 2024
1 parent c9fb6d0 commit c1b796c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 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
10 changes: 5 additions & 5 deletions server/__tests__/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { JsonRpcClient } from "../../client";
import { Backoff } from "../../client/backoff";
import { testHttpServer } from "../testing/testExpressApp";

const SERVER_RPC_PORT = 8080;
const SERVER_PROXY_PORT = 8081;
const TARGET_PORT = 8082;
const SERVER_RPC_PORT = 18080;
const SERVER_PROXY_PORT = 18081;
const TARGET_PORT = 18082;

type Client = {
jsonRpcClient: JsonRpcClient;
Expand Down Expand Up @@ -78,7 +78,7 @@ describe("Proxy server starts up first", () => {
).resolves.toMatchObject(
expect.objectContaining({
status: 502,
text: "Bad Gateway",
text: '{"error":{"type":"channel_not_found"},"message":"Error: Channel not found: testChannelId"}',
})
);
});
Expand All @@ -89,7 +89,7 @@ describe("Proxy server starts up first", () => {
).resolves.toMatchObject(
expect.objectContaining({
status: 502,
text: "Bad Gateway",
text: '{"error":{},"message":"Error: Client not found: noSuchClientId"}',
})
);
});
Expand Down
6 changes: 3 additions & 3 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 @@ -89,9 +89,9 @@ export const httpProxyApp = (
(error.message.startsWith("timeout") &&
error.message.endsWith("exceeded"))
) {
res.sendStatus(504);
res.status(504).json({ error, message: String(error) });
} else {
res.sendStatus(502);
res.status(502).json({ error, message: String(error) });
}
}
});
Expand Down

0 comments on commit c1b796c

Please sign in to comment.