wamp.rt
wamp.rt copied to clipboard
Send error message to client
I believe that if you returned an error as a response to a call, you should be able to read the error on the client
:+1:
Actually this is still wrong, look at the spec: https://github.com/wamp-proto/wamp-proto/blob/master/spec/basic.md#invocation-error
[ERROR, INVOCATION, INVOCATION.Request|id, Details|dict, Error|uri]
or
[ERROR, INVOCATION, INVOCATION.Request|id, Details|dict, Error|uri, Arguments|list]
or
[ERROR, INVOCATION, INVOCATION.Request|id, Details|dict, Error|uri, Arguments|list, ArgumentsKw|dict]
So, "wamp.error.callee_failure" should be replaced by err, and the additional parameters should also be added to the error message (args and kwargs, if they exists)
I believe this would be correct:
var resultCallback = function(err, args) {
var msg;
if (err) {
msg = [
WAMP.ERROR,
WAMP.CALL,
callId,
{},
err
];
} else {
msg = [
WAMP.RESULT,
callId,
{},
];
}
// Manage optional parameters args + kwargs
for(var i = 0; i < args.length && i < 2; i++) {
msg.push(args[i]);
}
session.send(msg);
};
The other problem with sending errors is in handlers[WAMP.ERROR]
handlers[WAMP.ERROR] = function(session, msg) {
var requestType = msg.shift();
var requestId = msg.shift();
var details = msg.shift();
var errorUri = msg.shift();
var args = msg.shift() || [];
var kwargs = msg.shift() || {};
var err = new Error(details); // <--- this line
if (requestType === WAMP.INVOCATION) {
// An invocation failed
var invId = requestId;
this.resrpc(invId, err, args); // <--- only err and args objects passed?
}
}
Several problems:
-
detailsare converted to anErrorobject, so this immediately becomes unusable for routing to the Caller (Errorobjects are not meaningfully JSON.stringified). - errorUri and kwargs are ignored? surely these should also be routed to the Caller.