Skip to content

Commit

Permalink
Merge pull request #58 from muzzammilshahid/handle-inv-error
Browse files Browse the repository at this point in the history
Handle error of invocation function
  • Loading branch information
muzzammilshahid authored Jul 30, 2024
2 parents f15ea45 + fd2d058 commit 4bea60b
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/src/session.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,18 @@ class Session {
} else if (message is msg.Invocation) {
var endpoint = _registrations[message.registrationID];
if (endpoint != null) {
Result result = endpoint(Invocation(args: message.args, kwargs: message.kwargs, details: message.details));
Object data = _wampSession.sendMessage(
msg.Yield(message.requestID, args: result.args, kwargs: result.kwargs, options: result.details),
);
msg.Message msgToSend;
try {
var result = endpoint(Invocation(args: message.args, kwargs: message.kwargs, details: message.details));
msgToSend = msg.Yield(message.requestID, args: result.args, kwargs: result.kwargs, options: result.details);
} on ApplicationError catch (e) {
msgToSend = msg.Error(message.messageType(), message.requestID, e.message, args: e.args, kwargs: e.kwargs);
} on Exception catch (e) {
msgToSend =
msg.Error(message.messageType(), message.requestID, "wamp.error.runtime_error", args: [e.toString()]);
}

Object data = _wampSession.sendMessage(msgToSend);
_baseSession.send(data);
}
} else if (message is msg.Unregistered) {
Expand Down

0 comments on commit 4bea60b

Please sign in to comment.