Respond to unhandled requests

Give an error response back to unhandled requests, this fixes requests
hanging forever when the target does not support the given request.
This commit is contained in:
Hornwitser committed 2020-11-12 04:05:24 +01:00
1 parent 42e680f09d
commit 49eb966315
2 files changed
+22

No files matched your search

+12
View File
@@ -39,6 +39,18 @@ class Link {
if (err.errors) {
console.error(err.errors);
}
// Send back an error response if this was a request.
if (
typeof payload.type === "string"
&& payload.type.endsWith("_request")
&& Number.isInteger(payload.seq)
) {
this.connector.send(
`${payload.type.slice(0, -8)}_response`,
{ seq: payload.seq, error: err.message }
);
}
} else {
this.connector.emit("error", err);
}
+10
View File
@@ -35,6 +35,16 @@ describe("lib/link/link", function() {
await assert.rejects(result, new Error("Handler error"));
});
it("should give an error response back on an unhandled request", function() {
testConnector.sentMessages = [];
testConnector.emit("message", { seq: 1, type: "unhandled_request", data: {}});
assert.deepEqual(testConnector.sentMessages, [{
type: "unhandled_response",
seq: testConnector._seq - 1,
data: { seq: 1, error: "No validator for unhandled_request on source-target" } },
])
});
describe(".setValidator()", function() {
it("should set the validator", function() {
testLink.setValidator("test", () => true);