diff --git a/src/App.tsx b/src/App.tsx index 7d1a803..e962335 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,6 +1,7 @@ import type { FC } from "react"; import { CastesLinks } from "./CastesLinks"; import { LocalLinks } from "./LocalLinks"; +import type { LinkInterface } from "./types"; function App() { const links = [ @@ -66,12 +67,6 @@ export const LinkGroup: FC = ({ title, links }) => { ); }; -interface LinkInterface { - name: string; - link: string; - icon?: string; -} - interface LinkProps { link: LinkInterface; } diff --git a/src/CastesLinks.tsx b/src/CastesLinks.tsx index 0fea6fb..fdec24a 100644 --- a/src/CastesLinks.tsx +++ b/src/CastesLinks.tsx @@ -1,10 +1,11 @@ import { useEffect, useState } from "react"; import { LinkGroup } from "./App"; +import type { ApiError, LinkInterface } from "./types"; export const CastesLinks = () => { const [loading, setLoading] = useState(true); const [error, setError] = useState(""); - const [links, setLinks] = useState([]); + const [links, setLinks] = useState([]); const castesLinks = [ { name: "GPAO", link: "http://gpao.lan" }, { name: "Penpot", link: "https://penpot.castes-industrie.fr" }, @@ -23,9 +24,13 @@ export const CastesLinks = () => { setLinks(castesLinks); } console.log("link", res); - } catch (error: Error | NetworkError | unknown) { + } catch (error: Error | ApiError | unknown) { console.log(error); - setError(error.response?.data.message || error.message); + if (error instanceof Error) { + console.error(error.message); + } else { + setError((error as ApiError).error); + } } finally { setLoading(false); } diff --git a/src/types.ts b/src/types.ts new file mode 100644 index 0000000..7088a21 --- /dev/null +++ b/src/types.ts @@ -0,0 +1,16 @@ +export interface ApiError { + error: string; + status?: number; +} + +export interface Link { + name: string; + url: string; + icon?: string | null; +} + +export interface LinkInterface { + name: string; + link: string; + icon?: string; +}