@@ -152,7 +152,8 @@ export class Connection {
152152 mechanism : this . params . mechanism ?? "PLAIN" ,
153153 } )
154154 const { heartbeat } = await this . tune ( this . params . heartbeat ?? 0 )
155- await this . open ( { virtualHost : this . params . vhost } )
155+ const connectionOpened = await this . open ( { virtualHost : this . params . vhost } )
156+ if ( ! connectionOpened . ok ) return rej ( connectionOpened . error )
156157 if ( ! this . heartbeat . started ) this . heartbeat . start ( heartbeat )
157158 await this . exchangeCommandVersions ( )
158159 this . setupCompleted = true
@@ -461,12 +462,25 @@ export class Connection {
461462
462463 private async open ( params : { virtualHost : string } ) {
463464 this . logger . debug ( `Open ...` )
465+ if ( this . virtualHostIsNotValid ( params . virtualHost ) ) {
466+ const errorMessage = `[ERROR]: VirtualHost '${ params . virtualHost } ' is not valid`
467+ this . logger . error ( errorMessage )
468+ return { ok : false , error : new Error ( errorMessage ) }
469+ }
464470 const res = await this . sendAndWait < OpenResponse > ( new OpenRequest ( params ) )
465471 this . logger . debug ( `Open response: ${ res . ok } - '${ inspect ( res . properties ) } '` )
466472 const advertisedHost = res . properties [ "advertised_host" ] ?? ""
467473 const advertisedPort = parseInt ( res . properties [ "advertised_port" ] ?? "5552" )
468474 this . serverEndpoint = { host : advertisedHost , port : advertisedPort }
469- return res
475+ return { ok : true , response : res }
476+ }
477+
478+ private virtualHostIsNotValid ( virtualHost : string ) {
479+ if ( ! virtualHost || virtualHost . split ( "/" ) . length !== 2 ) {
480+ return true
481+ }
482+
483+ return false
470484 }
471485
472486 private async tune ( heartbeatInterval : number ) : Promise < { heartbeat : number } > {
0 commit comments