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 {
28
28
29
29
onConnected ?: ( helloMessage : APIHello ) => void ;
30
30
onEvent ?: ( event : APIEvent ) => void ;
31
+ onError ?: ( error : APIError ) => void ;
31
32
32
33
constructor ( readonly token : string , readonly server = DEFAULT_SERVER ) {
33
34
this . socket = this . createSocket ( token , server ) ;
@@ -160,7 +161,14 @@ export class APIClient {
160
161
processMessage ( message : APIError | APIHello | APIEvent | APIResponse ) {
161
162
switch ( message . type ) {
162
163
case 'error' :
164
+ if ( this . onError ) {
165
+ this . onError ( message ) ;
166
+ }
163
167
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
+ }
164
172
break ;
165
173
166
174
case 'hello' :
Original file line number Diff line number Diff line change @@ -156,12 +156,17 @@ async function main() {
156
156
}
157
157
158
158
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
+
159
169
try {
160
- client . onConnected = ( hello ) => {
161
- if ( ! quiet ) {
162
- console . log ( `Connected to Wokwi Simulation API ${ hello . appVersion } ` ) ;
163
- }
164
- } ;
165
170
await client . connected ;
166
171
await client . fileUpload ( 'diagram.json' , diagram ) ;
167
172
const extension = firmwarePath . split ( '.' ) . pop ( ) ;
You can’t perform that action at this time.
0 commit comments