@@ -24,7 +24,7 @@ class _LobbyConnectionImpl {
2424 this . gameInstances . length = 0 ;
2525 const resp = await fetch ( this . _baseUrl ( ) ) ;
2626 if ( resp . status !== 200 ) {
27- throw 'HTTP status ' + resp . status ;
27+ throw new Error ( 'HTTP status ' + resp . status ) ;
2828 }
2929 const json = await resp . json ( ) ;
3030 for ( let gameName of json ) {
@@ -49,7 +49,7 @@ class _LobbyConnectionImpl {
4949
5050 _getGameComponents ( gameName ) {
5151 for ( let comp of this . gameComponents ) {
52- if ( comp . game . name == gameName ) return comp ;
52+ if ( comp . game . name === gameName ) return comp ;
5353 }
5454 }
5555
@@ -63,11 +63,11 @@ class _LobbyConnectionImpl {
6363 try {
6464 let inst = this . _findPlayer ( this . playerName ) ;
6565 if ( inst ) {
66- throw 'player has already joined ' + inst . gameID ;
66+ throw new Error ( 'player has already joined ' + inst . gameID ) ;
6767 }
6868 inst = this . _getGameInstance ( gameID ) ;
6969 if ( ! inst ) {
70- throw 'game instance ' + gameID + ' not found' ;
70+ throw new Error ( 'game instance ' + gameID + ' not found' ) ;
7171 }
7272 const resp = await fetch (
7373 this . _baseUrl ( ) + '/' + gameName + '/' + gameID + '/join' ,
@@ -80,7 +80,7 @@ class _LobbyConnectionImpl {
8080 headers : { 'Content-Type' : 'application/json' } ,
8181 }
8282 ) ;
83- if ( resp . status !== 200 ) throw 'HTTP status ' + resp . status ;
83+ if ( resp . status !== 200 ) throw new Error ( 'HTTP status ' + resp . status ) ;
8484 const json = await resp . json ( ) ;
8585 inst . players [ Number . parseInt ( playerID ) ] . name = this . playerName ;
8686 this . playerCredentials = json . playerCredentials ;
@@ -92,7 +92,7 @@ class _LobbyConnectionImpl {
9292 async leave ( gameName , gameID ) {
9393 try {
9494 let inst = this . _getGameInstance ( gameID ) ;
95- if ( ! inst ) throw 'game instance not found' ;
95+ if ( ! inst ) throw new Error ( 'game instance not found' ) ;
9696 for ( let player of inst . players ) {
9797 if ( player . name === this . playerName ) {
9898 const resp = await fetch (
@@ -106,13 +106,15 @@ class _LobbyConnectionImpl {
106106 headers : { 'Content-Type' : 'application/json' } ,
107107 }
108108 ) ;
109- if ( resp . status !== 200 ) throw 'HTTP status ' + resp . status ;
109+ if ( resp . status !== 200 ) {
110+ throw new Error ( 'HTTP status ' + resp . status ) ;
111+ }
110112 delete player . name ;
111113 delete this . playerCredentials ;
112114 return ;
113115 }
114116 }
115- throw 'player not found in room' ;
117+ throw new Error ( 'player not found in room' ) ;
116118 } catch ( error ) {
117119 throw new Error ( 'failed to leave room ' + gameID + ' (' + error + ')' ) ;
118120 }
@@ -130,20 +132,20 @@ class _LobbyConnectionImpl {
130132 async create ( gameName , numPlayers ) {
131133 try {
132134 const comp = this . _getGameComponents ( gameName ) ;
133- if ( ! comp ) throw 'game not found' ;
135+ if ( ! comp ) throw new Error ( 'game not found' ) ;
134136 if (
135137 numPlayers < comp . game . minPlayers ||
136138 numPlayers > comp . game . maxPlayers
137139 )
138- throw 'invalid number of players ' + numPlayers ;
140+ throw new Error ( 'invalid number of players ' + numPlayers ) ;
139141 const resp = await fetch ( this . _baseUrl ( ) + '/' + gameName + '/create' , {
140142 method : 'POST' ,
141143 body : JSON . stringify ( {
142144 numPlayers : numPlayers ,
143145 } ) ,
144146 headers : { 'Content-Type' : 'application/json' } ,
145147 } ) ;
146- if ( resp . status !== 200 ) throw 'HTTP status ' + resp . status ;
148+ if ( resp . status !== 200 ) throw new Error ( 'HTTP status ' + resp . status ) ;
147149 } catch ( error ) {
148150 throw new Error (
149151 'failed to create room for ' + gameName + ' (' + error + ')'
0 commit comments