Skip to content

Commit

Permalink
fix: update using NotFoundError
Browse files Browse the repository at this point in the history
  • Loading branch information
ivyjeong13 committed Dec 17, 2024
1 parent c62bfc6 commit 5c599d4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useEffect, useState } from "react";
import useSWR from "swr";

import { ModelProvider } from "~/lib/model/modelProviders";
import { NotFoundError } from "~/lib/service/api/apiErrors";
import { ModelProviderApiService } from "~/lib/service/api/modelProviderApiService";

import { ModelProviderForm } from "~/components/model-providers/ModelProviderForm";
Expand Down Expand Up @@ -130,7 +131,15 @@ export function ModelProviderConfigureContent({
{
keepPreviousData: true,
// 404 -> no credential found, so don't retry
shouldRetryOnError: (error) => error.status !== 404,
shouldRetryOnError: (error) => {
if (
error instanceof NotFoundError &&
error.message.toLowerCase().includes("no credential found")
) {
return false;
}
return true;
},
}
);

Expand Down
1 change: 1 addition & 0 deletions ui/admin/app/lib/service/api/apiErrors.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export class ConflictError extends Error {}
export class BadRequestError extends Error {}
export class NotFoundError extends Error {}

// Errors that should trigger the error boundary
export class BoundaryError extends Error {}
Expand Down
5 changes: 5 additions & 0 deletions ui/admin/app/lib/service/api/primitives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
BadRequestError,
ConflictError,
ForbiddenError,
NotFoundError,
UnauthorizedError,
} from "~/lib/service/api/apiErrors";

Expand Down Expand Up @@ -64,6 +65,10 @@ export async function request<T, R = AxiosResponse<T>, D = unknown>({
});
}

if (isAxiosError(error) && error.response?.status === 404) {
throw new NotFoundError(error.response.data);
}

if (isAxiosError(error) && error.response?.status === 409) {
throw new ConflictError(error.response.data);
}
Expand Down

0 comments on commit 5c599d4

Please sign in to comment.