Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

fix(cli): respond with HTTP 400 validation_error on route validation errors (#1521)

Henry Sued431917050c
diff --git a/src/helpers/cliBridge.js b/src/helpers/cliBridge.js
index 68e6fa75d..672bf85b0 100644
--- a/src/helpers/cliBridge.js
+++ b/src/helpers/cliBridge.js
@@ -212,6 +212,10 @@ class CliBridge {
sendV1Error(res, 404, "not_found", err.message);
return;
}
+ if (err.code === "VALIDATION") {
+ sendV1Error(res, 400, "validation_error", err.message);
+ return;
+ }
debugLogger.error("CLI bridge route error", { error: err.message }, "cli-bridge");
sendV1Error(res, 500, "internal_error", err.message || "Internal server error");
}
diff --git a/test/helpers/cliBridgeDictionary.test.js b/test/helpers/cliBridgeDictionary.test.js
index 34fce1c86..f47bed72e 100644
--- a/test/helpers/cliBridgeDictionary.test.js
+++ b/test/helpers/cliBridgeDictionary.test.js
@@ -37,7 +37,8 @@ const CliBridge = require("../../src/helpers/cliBridge.js");
function isNativeBindingUnavailable(error) {
const message = String(error?.message || error);
return (
- message.includes("NODE_MODULE_VERSION") || message.includes("Could not locate the bindings file")
+ message.includes("NODE_MODULE_VERSION") ||
+ message.includes("Could not locate the bindings file")
);
}
@@ -159,3 +160,87 @@ test("POST /v1/dictionary/update rejects an empty request", (t) => {
code: "VALIDATION",
});
});
+
+test("route validation errors respond with HTTP 400 validation_error", async (t) => {
+ const ctx = createBridge(t);
+ if (!ctx) return;
+
+ ctx.bridge.token = "test-token";
+ ctx.bridge.port = 8200;
+
+ class MockResponse {
+ constructor() {
+ this.statusCode = null;
+ this.headers = {};
+ this.body = "";
+ }
+ writeHead(code, headers) {
+ this.statusCode = code;
+ this.headers = headers;
+ }
+ end(chunk) {
+ if (chunk) this.body += chunk;
+ }
+ }
+
+ const req = {
+ socket: { remoteAddress: "127.0.0.1" },
+ headers: { authorization: "Bearer test-token" },
+ method: "GET",
+ url: "/v1/notes/search",
+ };
+ const res = new MockResponse();
+
+ await ctx.bridge._handleRequest(req, res);
+
+ assert.equal(res.statusCode, 400);
+ const parsed = JSON.parse(res.body);
+ assert.equal(parsed.error.code, "validation_error");
+ assert.equal(parsed.error.message, "Search query is required");
+});
+
+test("POST /v1/dictionary/update responds with HTTP 400 validation_error for invalid payload", async (t) => {
+ const ctx = createBridge(t);
+ if (!ctx) return;
+
+ ctx.bridge.token = "test-token";
+ ctx.bridge.port = 8200;
+
+ class MockResponse {
+ constructor() {
+ this.statusCode = null;
+ this.headers = {};
+ this.body = "";
+ }
+ writeHead(code, headers) {
+ this.statusCode = code;
+ this.headers = headers;
+ }
+ end(chunk) {
+ if (chunk) this.body += chunk;
+ }
+ }
+
+ const req = {
+ socket: { remoteAddress: "127.0.0.1" },
+ headers: { authorization: "Bearer test-token" },
+ method: "POST",
+ url: "/v1/dictionary/update",
+ on(event, handler) {
+ if (event === "data") {
+ handler(JSON.stringify({ add: "not-an-array" }));
+ }
+ if (event === "end") {
+ handler();
+ }
+ },
+ };
+ const res = new MockResponse();
+
+ await ctx.bridge._handleRequest(req, res);
+
+ assert.equal(res.statusCode, 400);
+ const parsed = JSON.parse(res.body);
+ assert.equal(parsed.error.code, "validation_error");
+ assert.equal(parsed.error.message, "'add' must be an array of strings");
+});