wamp.rt icon indicating copy to clipboard operation
wamp.rt copied to clipboard

Send error message to client

Open adlerparnas opened this issue 10 years ago • 4 comments

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

adlerparnas avatar Jun 16 '15 03:06 adlerparnas

:+1:

speigg avatar Sep 30 '15 15:09 speigg

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)

speigg avatar Sep 30 '15 15:09 speigg

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);
};

speigg avatar Sep 30 '15 15:09 speigg

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:

  1. details are converted to an Error object, so this immediately becomes unusable for routing to the Caller (Error objects are not meaningfully JSON.stringified).
  2. errorUri and kwargs are ignored? surely these should also be routed to the Caller.

speigg avatar Sep 30 '15 16:09 speigg