Skip to content

Commit 03eadb6

Browse files
committed
Handle errors
1 parent b7ccb0f commit 03eadb6

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

site/src/xServices/audit/auditXService.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { getAuditLogs } from "api/api"
2+
import { getErrorMessage } from "api/errors"
3+
import { displayError } from "components/GlobalSnackbar/utils"
24
import { assign, createMachine } from "xstate"
35

46
type AuditLogs = Awaited<ReturnType<typeof getAuditLogs>>
@@ -24,18 +26,29 @@ export const auditMachine = createMachine(
2426
target: "success",
2527
actions: ["assignAuditLogs"],
2628
},
29+
onError: {
30+
target: "error",
31+
actions: ["displayLoadAuditLogsError"],
32+
},
2733
},
2834
},
2935
success: {
3036
type: "final",
3137
},
38+
error: {
39+
type: "final",
40+
},
3241
},
3342
},
3443
{
3544
actions: {
3645
assignAuditLogs: assign({
3746
auditLogs: (_, event) => event.data,
3847
}),
48+
displayLoadAuditLogsError: (_, event) => {
49+
const message = getErrorMessage(event.data, "Error on loading audit logs.")
50+
displayError(message)
51+
},
3952
},
4053
services: {
4154
loadAuditLogs: () => getAuditLogs(),

0 commit comments

Comments
 (0)