File tree Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ export class APIClient {
2828
2929 onConnected ?: ( helloMessage : APIHello ) => void ;
3030 onEvent ?: ( event : APIEvent ) => void ;
31+ onError ?: ( error : APIError ) => void ;
3132
3233 constructor ( readonly token : string , readonly server = DEFAULT_SERVER ) {
3334 this . socket = this . createSocket ( token , server ) ;
@@ -160,7 +161,14 @@ export class APIClient {
160161 processMessage ( message : APIError | APIHello | APIEvent | APIResponse ) {
161162 switch ( message . type ) {
162163 case 'error' :
164+ if ( this . onError ) {
165+ this . onError ( message ) ;
166+ }
163167 console . error ( 'API Error:' , message . message ) ;
168+ if ( this . pendingCommands . size > 0 ) {
169+ const [ , reject ] = this . pendingCommands . values ( ) . next ( ) . value ;
170+ reject ( new Error ( message . message ) ) ;
171+ }
164172 break ;
165173
166174 case 'hello' :
Original file line number Diff line number Diff line change @@ -156,12 +156,17 @@ async function main() {
156156 }
157157
158158 const client = new APIClient ( token ) ;
159+ client . onConnected = ( hello ) => {
160+ if ( ! quiet ) {
161+ console . log ( `Connected to Wokwi Simulation API ${ hello . appVersion } ` ) ;
162+ }
163+ } ;
164+ client . onError = ( error ) => {
165+ console . error ( 'API Error:' , error . message ) ;
166+ process . exit ( 1 ) ;
167+ } ;
168+
159169 try {
160- client . onConnected = ( hello ) => {
161- if ( ! quiet ) {
162- console . log ( `Connected to Wokwi Simulation API ${ hello . appVersion } ` ) ;
163- }
164- } ;
165170 await client . connected ;
166171 await client . fileUpload ( 'diagram.json' , diagram ) ;
167172 const extension = firmwarePath . split ( '.' ) . pop ( ) ;
You can’t perform that action at this time.
0 commit comments