Skip to content

Commit

Permalink
Merge pull request #245 from KSDaemon/conn-abort-handle
Browse files Browse the repository at this point in the history
fix: rejecting connection promise on ABORT message
  • Loading branch information
KSDaemon authored Jan 9, 2023
2 parents 2f31833 + 58e77ab commit 1dc0539
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/wampy.js
Original file line number Diff line number Diff line change
Expand Up @@ -946,8 +946,13 @@ class Wampy {
* @private
*/
async _onAbortMessage ([, details, error]) {
const err = new Errors.AbortError({ error, details });
if (this._cache.connectPromise) {
this._cache.connectPromise.onError(err);
this._cache.connectPromise = null;
}
if (this._options.onError) {
await this._options.onError(new Errors.AbortError({ error, details }));
await this._options.onError(err);
}
this._ws.close();
}
Expand Down
10 changes: 10 additions & 0 deletions test/send-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ const WAMP_MSG_SPEC = {
],
ruinMessage: true
},
// reject connection promise if receives ABORT message
{
data: [
WAMP_MSG_SPEC.ABORT,
{
info: 'Just testing abort connection',
},
'wamp.error.not_authorized'
]
},
// passes welcome details to onConnect() callback
{
data: [
Expand Down
13 changes: 13 additions & 0 deletions test/wampy-common-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,19 @@ serializers.forEach(function (item) {
});
});

it('reject connection promise if receives ABORT message', async function () {
const wampy = new Wampy(routerUrl, {
realm : 'AppRealm',
ws,
serializer: new serializer()
});
try {
await wampy.connect();
} catch (e) {
expect(e).to.be.instanceOf(Errors.AbortError);
}
});

it('passes welcome details to onConnect() callback', async function () {
const wampy = new Wampy(routerUrl, {
realm : 'AppRealm',
Expand Down

0 comments on commit 1dc0539

Please sign in to comment.