fix: add error handling and use existing utility

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-03-04 02:08:09 +08:00
parent fdeb42f212
commit df5c0b4237

View File

@@ -3,8 +3,15 @@
import { useState } from 'react';
import useSWR from 'swr';
import { formatVersion } from '@/lib/fs-utils';
const fetcher = (url: string) => fetch(url).then((res) => res.json());
const fetcher = async (url: string) => {
const res = await fetch(url);
if (!res.ok) {
throw new Error(`HTTP error: ${res.status}`);
}
return res.json();
};
interface SearchFormProps {
onSearch: (project: string, version: string, commitId: string) => void;
@@ -81,7 +88,7 @@ export default function SearchForm({ onSearch }: SearchFormProps) {
) : (
versions?.map((version: string) => (
<option key={version} value={version}>
{version.replace('_', '.')}
{formatVersion(version)}
</option>
))
)}