@@ -130,7 +130,11 @@ public void handlePublish(BsonObject frame) {
130130 };
131131
132132 authorisedCF .handle ((res , ex ) -> {
133- handleFrame (frame , frameConsumer , res , ex );
133+ if (ex != null ) {
134+ sendErrorResponse (Client .ERR_AUTHORISATION_FAILED , "Authorisation failed" , frame .getInteger (Protocol .REQUEST_REQUEST_ID ));
135+ logAndClose (ex .getMessage ());
136+ }
137+ handleFrame (frame , frameConsumer , res );
134138 return null ;
135139 });
136140 }
@@ -203,7 +207,11 @@ public void handleSubscribe(BsonObject frame) {
203207 };
204208
205209 authorisedCF .handle ((res , ex ) -> {
206- handleFrame (frame , frameConsumer , res , ex );
210+ if (ex != null ) {
211+ sendErrorResponse (Client .ERR_AUTHORISATION_FAILED , "Authorisation failed" , frame .getInteger (Protocol .REQUEST_REQUEST_ID ));
212+ logAndClose (ex .getMessage ());
213+ }
214+ handleFrame (frame , frameConsumer , res );
207215 return null ;
208216 });
209217
@@ -239,8 +247,11 @@ public void handleSubClose(BsonObject frame) {
239247 };
240248
241249 authorisedCF .handle ((res , ex ) -> {
242-
243- handleFrame (frame , frameConsumer , res , ex );
250+ if (ex != null ) {
251+ sendErrorResponse (Client .ERR_AUTHORISATION_FAILED , "Authorisation failed" , frame .getInteger (Protocol .REQUEST_REQUEST_ID ));
252+ logAndClose (ex .getMessage ());
253+ }
254+ handleFrame (frame , frameConsumer , res );
244255 return null ;
245256 });
246257 }
@@ -277,8 +288,11 @@ public void handleUnsubscribe(BsonObject frame) {
277288 };
278289
279290 authorisedCF .handle ((res , ex ) -> {
280-
281- handleFrame (frame , frameConsumer , res , ex );
291+ if (ex != null ) {
292+ sendErrorResponse (Client .ERR_AUTHORISATION_FAILED , "Authorisation failed" , frame .getInteger (Protocol .REQUEST_REQUEST_ID ));
293+ logAndClose (ex .getMessage ());
294+ }
295+ handleFrame (frame , frameConsumer , res );
282296 return null ;
283297 });
284298 }
@@ -314,8 +328,11 @@ public void handleAckEv(BsonObject frame) {
314328 };
315329
316330 authorisedCF .handle ((res , ex ) -> {
317-
318- handleFrame (frame , frameConsumer , res , ex );
331+ if (ex != null ) {
332+ sendErrorResponse (Client .ERR_AUTHORISATION_FAILED , "Authorisation failed" , frame .getInteger (Protocol .REQUEST_REQUEST_ID ));
333+ logAndClose (ex .getMessage ());
334+ }
335+ handleFrame (frame , frameConsumer , res );
319336 return null ;
320337 });
321338 }
@@ -354,8 +371,11 @@ public void handleQuery(BsonObject frame) {
354371 };
355372
356373 authorisedCF .handle ((res , ex ) -> {
357-
358- handleFrame (frame , frameConsumer , res , ex );
374+ if (ex != null ) {
375+ sendErrorResponse (Client .ERR_AUTHORISATION_FAILED , "Authorisation failed" , frame .getInteger (Protocol .REQUEST_REQUEST_ID ));
376+ logAndClose (ex .getMessage ());
377+ }
378+ handleFrame (frame , frameConsumer , res );
359379 return null ;
360380 });
361381 }
@@ -384,8 +404,11 @@ public void handleQueryAck(BsonObject frame) {
384404 };
385405
386406 authorisedCF .handle ((res , ex ) -> {
387-
388- handleFrame (frame , frameConsumer , res , ex );
407+ if (ex != null ) {
408+ sendErrorResponse (Client .ERR_AUTHORISATION_FAILED , "Authorisation failed" );
409+ logAndClose (ex .getMessage ());
410+ }
411+ handleFrame (frame , frameConsumer , res );
389412 return null ;
390413 });
391414 }
@@ -422,8 +445,11 @@ public void handleListBinders(BsonObject frame) {
422445 };
423446
424447 authorisedCF .handle ((res , ex ) -> {
425-
426- handleFrame (frame , frameConsumer , res , ex );
448+ if (ex != null ) {
449+ sendErrorResponse (Client .ERR_AUTHORISATION_FAILED , "Authorisation failed" , frame .getInteger (Protocol .REQUEST_REQUEST_ID ));
450+ logAndClose (ex .getMessage ());
451+ }
452+ handleFrame (frame , frameConsumer , res );
427453 return null ;
428454 });
429455 }
@@ -461,8 +487,11 @@ public void handleCreateBinder(BsonObject frame) {
461487 };
462488
463489 authorisedCF .handle ((res , ex ) -> {
464-
465- handleFrame (frame , frameConsumer , res , ex );
490+ if (ex != null ) {
491+ sendErrorResponse (Client .ERR_AUTHORISATION_FAILED , "Authorisation failed" , frame .getInteger (Protocol .REQUEST_REQUEST_ID ));
492+ logAndClose (ex .getMessage ());
493+ }
494+ handleFrame (frame , frameConsumer , res );
466495 return null ;
467496 });
468497 }
@@ -488,8 +517,11 @@ public void handleListChannels(BsonObject frame) {
488517 };
489518
490519 authorisedCF .handle ((res , ex ) -> {
491-
492- handleFrame (frame , frameConsumer , res , ex );
520+ if (ex != null ) {
521+ sendErrorResponse (Client .ERR_AUTHORISATION_FAILED , "Authorisation failed" , frame .getInteger (Protocol .REQUEST_REQUEST_ID ));
522+ logAndClose (ex .getMessage ());
523+ }
524+ handleFrame (frame , frameConsumer , res );
493525 return null ;
494526 });
495527 }
@@ -527,22 +559,22 @@ public void handleCreateChannel(BsonObject frame) {
527559 };
528560
529561 authorisedCF .handle ((res , ex ) -> {
530-
531- handleFrame (frame , frameConsumer , res , ex );
562+ if (ex != null ) {
563+ sendErrorResponse (Client .ERR_AUTHORISATION_FAILED , "Authorisation failed" , frame .getInteger (Protocol .REQUEST_REQUEST_ID ));
564+ logAndClose (ex .getMessage ());
565+ }
566+ handleFrame (frame , frameConsumer , res );
532567 return null ;
533568 });
534569
535570 }
536571
537- private void handleFrame (BsonObject frame , Consumer <BsonObject > consumer , boolean res , Throwable ex ) {
538- if (ex != null ) {
539- sendErrorResponse (Client .ERR_AUTHORISATION_FAILED , "An error occurred when authorising user" );
540- logAndClose (ex .getMessage ());
541- } else if (res ){
572+ private void handleFrame (BsonObject frame , Consumer <BsonObject > consumer , boolean res ) {
573+ if (res ){
542574 consumer .accept (frame );
543575 } else {
544- sendErrorResponse (Client .ERR_NOT_AUTHORISED , "User is not authorised" );
545- logAndClose (ex . getMessage () );
576+ sendErrorResponse (Client .ERR_NOT_AUTHORISED , "User is not authorised" , frame . getInteger ( Protocol . REQUEST_REQUEST_ID ) );
577+ logAndClose ("User is not authorised" );
546578 }
547579 }
548580
0 commit comments