| @@ -1,11 +1,10 @@ | |||||
| import axios from 'axios' | |||||
| import { useEffect, useState } from 'react' | import { useEffect, useState } from 'react' | ||||
| import { BrowserRouter, Navigate, Route, Routes, useLocation } from 'react-router-dom' | import { BrowserRouter, Navigate, Route, Routes, useLocation } from 'react-router-dom' | ||||
| import RouteBlockerOverlay from '@/components/RouteBlockerOverlay' | import RouteBlockerOverlay from '@/components/RouteBlockerOverlay' | ||||
| import TopNav from '@/components/TopNav' | import TopNav from '@/components/TopNav' | ||||
| import { Toaster } from '@/components/ui/toaster' | import { Toaster } from '@/components/ui/toaster' | ||||
| import { apiPost } from '@/lib/api' | |||||
| import { apiPost, isApiError } from '@/lib/api' | |||||
| import NicoTagListPage from '@/pages/tags/NicoTagListPage' | import NicoTagListPage from '@/pages/tags/NicoTagListPage' | ||||
| import NotFound from '@/pages/NotFound' | import NotFound from '@/pages/NotFound' | ||||
| import PostDetailPage from '@/pages/posts/PostDetailPage' | import PostDetailPage from '@/pages/posts/PostDetailPage' | ||||
| @@ -61,8 +60,8 @@ export default (() => { | |||||
| } | } | ||||
| catch (err) | catch (err) | ||||
| { | { | ||||
| if (axios.isAxiosError (err)) | |||||
| setStatus (err.status ?? 200) | |||||
| if (isApiError (err)) | |||||
| setStatus (err.response?.status ?? 200) | |||||
| } | } | ||||
| }) () | }) () | ||||
| } | } | ||||
| @@ -3,6 +3,8 @@ import toCamel from 'camelcase-keys' | |||||
| import { API_BASE_URL } from '@/config' | import { API_BASE_URL } from '@/config' | ||||
| import type { AxiosError } from 'axios' | |||||
| type Opt = { | type Opt = { | ||||
| params?: Record<string, unknown> | params?: Record<string, unknown> | ||||
| headers?: Record<string, string> | headers?: Record<string, string> | ||||
| @@ -64,3 +66,7 @@ export const apiDelete = async ( | |||||
| ): Promise<void> => { | ): Promise<void> => { | ||||
| await client.delete (path, withUserCode (opt)) | await client.delete (path, withUserCode (opt)) | ||||
| } | } | ||||
| export const isApiError = (err: unknown): err is AxiosError => | |||||
| axios.isAxiosError (err) | |||||
| @@ -1,4 +1,4 @@ | |||||
| import React, { useEffect, useState } from 'react' | |||||
| import { useEffect, useState } from 'react' | |||||
| import { Helmet } from 'react-helmet-async' | import { Helmet } from 'react-helmet-async' | ||||
| import PrefetchLink from '@/components/PrefetchLink' | import PrefetchLink from '@/components/PrefetchLink' | ||||
| @@ -7,6 +7,8 @@ import MainArea from '@/components/layout/MainArea' | |||||
| import { SITE_TITLE } from '@/config' | import { SITE_TITLE } from '@/config' | ||||
| import { apiGet } from '@/lib/api' | import { apiGet } from '@/lib/api' | ||||
| import type { FormEvent } from 'react' | |||||
| import type { WikiPage } from '@/types' | import type { WikiPage } from '@/types' | ||||
| @@ -19,7 +21,7 @@ export default () => { | |||||
| setResults (await apiGet ('/wiki', { params: { title } })) | setResults (await apiGet ('/wiki', { params: { title } })) | ||||
| } | } | ||||
| const handleSearch = (ev: React.FormEvent) => { | |||||
| const handleSearch = (ev: FormEvent) => { | |||||
| ev.preventDefault () | ev.preventDefault () | ||||
| search () | search () | ||||
| } | } | ||||