Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error reporting to server consumers #29

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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" });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this more REST-compatible, by treating the location as a resource reference.

}

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
Loading