Skip to content

Commit

Permalink
feat(txs-tracer-core): ✨ improve error handling
Browse files Browse the repository at this point in the history
improved error handling on ibc trace machine
  • Loading branch information
DavideSegullo committed Mar 7, 2023
1 parent dd1ac1e commit ef17dc8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ export const ibcTraceMachine = createMachine(
return (
event.data.state === TxTraceFinalState.Result &&
event.data.txs !== undefined &&
event.data.txs.length > 0
event.data.txs.length > 0 &&
event.data.txs[0].code === 0
);
},
actions: raise<
Expand All @@ -77,6 +78,10 @@ export const ibcTraceMachine = createMachine(
type: 'ON_ERROR',
data: {
state: event.data.state,
code:
event.data.txs && event.data.txs.length > 0
? event.data.txs[0].code
: -1,
},
})),
},
Expand All @@ -101,6 +106,11 @@ export const ibcTraceMachine = createMachine(
},
ON_ERROR: {
target: 'error',
actions: assign({
errorCode: (_, event) => {
return event.data.code;
},
}),
},
},
},
Expand Down Expand Up @@ -136,6 +146,10 @@ export const ibcTraceMachine = createMachine(
type: 'ON_ERROR',
data: {
state: event.data.state,
code:
event.data.txs && event.data.txs.length > 0
? event.data.txs[0].code
: -1,
},
})),
},
Expand Down Expand Up @@ -182,6 +196,11 @@ export const ibcTraceMachine = createMachine(
},
ON_ERROR: {
target: 'error',
actions: assign({
errorCode: (_, event) => {
return event.data.code;
},
}),
},
},
},
Expand All @@ -203,6 +222,7 @@ export const ibcTraceMachine = createMachine(
websocketUrl: 'wss://rpc-osmosis.blockapsis.com',
loading: false,
currentStep: 0,
errorCode: 0,
query: '',
},
predictableActionArguments: true,
Expand Down
2 changes: 2 additions & 0 deletions packages/txs-tracer-core/src/lib/types/ibc-trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ export type IBCTraceContext = Omit<
> & {
loading: boolean;
currentStep: number;
errorCode?: number;
};

export type IBCTraceEventPayload = TxTraceEventPayload;

export type IBCMachineResultErrorPayload = {
type: TxTraceFinalStates;
code: number;
};

export type IBCTraceAckEventPayload = {
Expand Down

0 comments on commit ef17dc8

Please sign in to comment.