Import and use axiosError

This commit is contained in:
Weitheng Haw 2025-01-28 09:54:38 +00:00
parent 08f97c3aaf
commit b8c93632f0

View File

@ -21,7 +21,7 @@ import {
import useOptimisticState from "@/hooks/use-optimistic-state"; import useOptimisticState from "@/hooks/use-optimistic-state";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
import { FrigateConfig } from "@/types/frigateConfig"; import { FrigateConfig } from "@/types/frigateConfig";
import axios from "axios"; import axios, { AxiosError } from "axios";
import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { LuImagePlus, LuTrash2, LuUserPlus, LuEdit } from "react-icons/lu"; import { LuImagePlus, LuTrash2, LuUserPlus, LuEdit } from "react-icons/lu";
import { toast } from "sonner"; import { toast } from "sonner";
@ -150,8 +150,9 @@ export default function FaceLibrary() {
toast.success("Successfully created new face", { position: "top-center" }); toast.success("Successfully created new face", { position: "top-center" });
} }
} catch (error) { } catch (error) {
const axiosError = error as AxiosError<{ message: string }>;
toast.error( toast.error(
`Failed to create face: ${error.response?.data?.message || error.message}`, `Failed to create face: ${axiosError.response?.data?.message || axiosError.message}`,
{ position: "top-center" } { position: "top-center" }
); );
} finally { } finally {
@ -195,8 +196,9 @@ export default function FaceLibrary() {
refreshFaces(); refreshFaces();
toast.success("Successfully renamed face", { position: "top-center" }); toast.success("Successfully renamed face", { position: "top-center" });
} catch (error) { } catch (error) {
const axiosError = error as AxiosError<{ message: string }>;
toast.error( toast.error(
`Failed to rename face: ${error.response?.data?.message || error.message}`, `Failed to rename face: ${axiosError.response?.data?.message || axiosError.message}`,
{ position: "top-center" } { position: "top-center" }
); );
} finally { } finally {