Skip to content

Commit ea7454d

Browse files
committed
add socket error handler
1 parent 75640ea commit ea7454d

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

app/src/utils/proving/provingMachine.ts

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,37 @@ export const useProvingStore = create<ProvingState>((set, get) => {
417417
trackEvent(ProofEvents.SOCKETIO_SUBSCRIBED);
418418
});
419419

420+
socket.on('connect_error', error => {
421+
console.error('SocketIO connection error:', error);
422+
trackEvent(ProofEvents.SOCKETIO_CONNECT_ERROR, {
423+
message: (error as any).message,
424+
});
425+
trackEvent(ProofEvents.PROOF_FAILED, {
426+
circuitType: get().circuitType,
427+
error: get().error_code ?? 'unknown',
428+
});
429+
actor!.send({ type: 'PROVE_ERROR' });
430+
set({ socketConnection: null });
431+
});
432+
433+
socket.on('disconnect', (reason: string) => {
434+
console.log(`SocketIO disconnected. Reason: ${reason}`);
435+
const currentActor = actor;
436+
437+
if (get().currentState === 'ready_to_prove' && currentActor) {
438+
console.error(
439+
'SocketIO disconnected unexpectedly during proof listening.',
440+
);
441+
trackEvent(ProofEvents.SOCKETIO_DISCONNECT_UNEXPECTED);
442+
trackEvent(ProofEvents.PROOF_FAILED, {
443+
circuitType: get().circuitType,
444+
error: get().error_code ?? 'unknown',
445+
});
446+
currentActor.send({ type: 'PROVE_ERROR' });
447+
}
448+
set({ socketConnection: null });
449+
});
450+
420451
socket.on('status', (message: any) => {
421452
const data =
422453
typeof message === 'string' ? JSON.parse(message) : message;
@@ -451,37 +482,6 @@ export const useProvingStore = create<ProvingState>((set, get) => {
451482
actor!.send({ type: 'PROVE_SUCCESS' });
452483
}
453484
});
454-
455-
socket.on('disconnect', (reason: string) => {
456-
console.log(`SocketIO disconnected. Reason: ${reason}`);
457-
const currentActor = actor;
458-
459-
if (get().currentState === 'ready_to_prove' && currentActor) {
460-
console.error(
461-
'SocketIO disconnected unexpectedly during proof listening.',
462-
);
463-
trackEvent(ProofEvents.SOCKETIO_DISCONNECT_UNEXPECTED);
464-
trackEvent(ProofEvents.PROOF_FAILED, {
465-
circuitType: get().circuitType,
466-
error: get().error_code ?? 'unknown',
467-
});
468-
currentActor.send({ type: 'PROVE_ERROR' });
469-
}
470-
set({ socketConnection: null });
471-
});
472-
473-
socket.on('connect_error', error => {
474-
console.error('SocketIO connection error:', error);
475-
trackEvent(ProofEvents.SOCKETIO_CONNECT_ERROR, {
476-
message: (error as any).message,
477-
});
478-
trackEvent(ProofEvents.PROOF_FAILED, {
479-
circuitType: get().circuitType,
480-
error: get().error_code ?? 'unknown',
481-
});
482-
actor!.send({ type: 'PROVE_ERROR' });
483-
set({ socketConnection: null });
484-
});
485485
},
486486

487487
_handleWsOpen: () => {

0 commit comments

Comments
 (0)