Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement dispatching custom error remote functions #1356

Merged
merged 10 commits into from
Jul 22, 2024

Conversation

Bhashinee
Copy link
Member

@Bhashinee Bhashinee commented Jun 20, 2024

Purpose

Introduce support to dispatch custom error remote functions. When there is a data binding error related to a custom remote function, if the WebSocket service has a custom error remote function associated with that particular custom remote function, that error remote function will get dispatched.

Related issue: ballerina-platform/ballerina-library#6625

Examples

For example,

@websocket:ServiceConfig {dispatcherKey: "event"}
service /oncustomerror on customDispatchingLis {
    resource function get .() returns websocket:Service|websocket:Error {
        return new OnCustomErrorService();
    }
}

service class OnCustomErrorService {
    *websocket:Service;
    remote function onSubscribe(websocket:Caller caller, byte[] data) returns Error? {
        check caller->writeMessage({"event": "onMessages"});
    }

    remote function onSubscribeError(websocket:Caller caller, error err) returns Error? {
        check caller->writeMessage({"event": "onCustomError"});
    }
}

Checklist

  • Linked to an issue
  • Updated the specification
  • Updated the changelog
  • Added tests
  • Checked native-image compatibility

@Bhashinee Bhashinee requested a review from shafreenAnfar as a code owner June 20, 2024 08:58
@Bhashinee Bhashinee changed the title Implement dispatching to custom remote functions Implement dispatching to custom error remote functions Jun 20, 2024
@Bhashinee Bhashinee changed the title Implement dispatching to custom error remote functions Implement dispatching custom error remote functions Jun 20, 2024
Comment on lines 570 to 574
private static String getCustomRemoteMethodName(String dispatchingKey,
WebSocketConnectionInfo.StringAggregator stringAggregator) {
if (null == dispatchingKey) {
return null;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we use optionals here rather than using null ?

// If any runtime error occurs while retrieving the dispatching value, the default method(onMessage)
// name will be used.
} catch (RuntimeException e) {
return null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in affa6f8

Copy link

This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the stale label is removed or commented.

@github-actions github-actions bot added the Stale label Jul 13, 2024
@Bhashinee Bhashinee removed the Stale label Jul 14, 2024
@Bhashinee Bhashinee merged commit abc2f93 into ballerina-platform:main Jul 22, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants