use parseError

This commit is contained in:
Oliver Bryan
2026-01-13 15:34:15 +00:00
parent ca371b1751
commit dc566260d8
10 changed files with 73 additions and 70 deletions

View File

@@ -1,7 +1,7 @@
import type { TimerState } from "@issue/shared";
import { useEffect, useState } from "react";
import { toast } from "sonner";
import { timer } from "@/lib/server";
import { parseError, timer } from "@/lib/server";
import { formatTime } from "@/lib/utils";
const FALLBACK_TIME = "--:--:--";
@@ -25,11 +25,12 @@ export function TimerDisplay({ issueId }: { issueId: number }) {
setWorkTimeMs(data?.workTimeMs ?? 0);
setError(null);
},
onError: (error) => {
onError: (err) => {
if (!isMounted) return;
setError(error);
const message = parseError(err);
setError(message);
toast.error(`Error fetching timer data: ${error}`, {
toast.error(`Error fetching timer data: ${message}`, {
dismissible: false,
});
},
@@ -39,19 +40,19 @@ export function TimerDisplay({ issueId }: { issueId: number }) {
issueId,
onSuccess: (data) => {
if (!isMounted) return;
const sessions = (data ?? []) as TimerState[];
const totalWorkTime = sessions.reduce(
const totalWorkTime = data.reduce(
(total, session) => total + (session?.workTimeMs ?? 0),
0,
);
setInactiveWorkTimeMs(totalWorkTime);
setError(null);
},
onError: (error) => {
onError: (err) => {
if (!isMounted) return;
setError(error);
const message = parseError(err);
setError(message);
toast.error(`Error fetching timer data: ${error}`, {
toast.error(`Error fetching timer data: ${message}`, {
dismissible: false,
});
},