fix(init): use isAxiosError to correctly detect 404 on project name availability check
This commit is contained in:
parent
f5084974b3
commit
41f96af064
@ -4,6 +4,7 @@ import {useQuery} from '@tanstack/react-query';
|
||||
import {CheckCircle2, Loader2, XCircle} from 'lucide-react';
|
||||
import {toast} from 'sonner';
|
||||
import {projectCreate, projectInfo, workspaceList} from '@/client';
|
||||
import {isAxiosError} from 'axios';
|
||||
import {Button} from '@/components/ui/button';
|
||||
import {Input} from '@/components/ui/input';
|
||||
import {Label} from '@/components/ui/label';
|
||||
@ -59,11 +60,12 @@ export function InitProject() {
|
||||
try {
|
||||
const lower = name.trim().toLowerCase();
|
||||
await projectInfo({path: {project_name: lower}});
|
||||
// 200 OK → 项目存在
|
||||
setNameAvailable(false);
|
||||
setAvailabilityMessage('Project name already exists');
|
||||
} catch (err: unknown) {
|
||||
const status = (err as any)?.response?.status;
|
||||
if (status === 404) {
|
||||
// @hey-api/openapi-ts 默认 throwOnError=false,错误作为 AxiosError 返回
|
||||
if (isAxiosError(err) && err.response?.status === 404) {
|
||||
setNameAvailable(true);
|
||||
setAvailabilityMessage('Project name is available');
|
||||
} else {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user