Merge pull request #366 from langflow-ai/dont-show-banner-when-down
dont show banner when down
This commit is contained in:
commit
43f8ec0e81
2 changed files with 52 additions and 19 deletions
|
|
@ -23,8 +23,12 @@ export function useProviderHealth() {
|
||||||
} = useProviderHealthQuery();
|
} = useProviderHealthQuery();
|
||||||
|
|
||||||
const isHealthy = health?.status === "healthy" && !isError;
|
const isHealthy = health?.status === "healthy" && !isError;
|
||||||
|
// Only consider unhealthy if backend is up but provider validation failed
|
||||||
|
// Don't show banner if backend is unavailable
|
||||||
const isUnhealthy =
|
const isUnhealthy =
|
||||||
health?.status === "unhealthy" || health?.status === "error" || isError;
|
health?.status === "unhealthy" || health?.status === "error";
|
||||||
|
const isBackendUnavailable =
|
||||||
|
health?.status === "backend-unavailable" || isError;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
health,
|
health,
|
||||||
|
|
@ -34,17 +38,23 @@ export function useProviderHealth() {
|
||||||
isError,
|
isError,
|
||||||
isHealthy,
|
isHealthy,
|
||||||
isUnhealthy,
|
isUnhealthy,
|
||||||
|
isBackendUnavailable,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ProviderHealthBanner({ className }: ProviderHealthBannerProps) {
|
export function ProviderHealthBanner({ className }: ProviderHealthBannerProps) {
|
||||||
const { isLoading, isHealthy, error } = useProviderHealth();
|
const { isLoading, isHealthy, isUnhealthy, health } = useProviderHealth();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const { data: settings = {} } = useGetSettingsQuery();
|
const { data: settings = {} } = useGetSettingsQuery();
|
||||||
|
|
||||||
if (!isHealthy && !isLoading) {
|
// Only show banner when provider is unhealthy (not when backend is unavailable)
|
||||||
const errorMessage = error?.message || "Provider validation failed";
|
if (isLoading || isHealthy) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isUnhealthy) {
|
||||||
|
const errorMessage = health?.message || "Provider validation failed";
|
||||||
const settingsUrl = settings.provider?.model_provider
|
const settingsUrl = settings.provider?.model_provider
|
||||||
? `/settings?setup=${settings.provider?.model_provider}`
|
? `/settings?setup=${settings.provider?.model_provider}`
|
||||||
: "/settings";
|
: "/settings";
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ export interface ProviderHealthDetails {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ProviderHealthResponse {
|
export interface ProviderHealthResponse {
|
||||||
status: "healthy" | "unhealthy" | "error";
|
status: "healthy" | "unhealthy" | "error" | "backend-unavailable";
|
||||||
message: string;
|
message: string;
|
||||||
provider: string;
|
provider: string;
|
||||||
details?: ProviderHealthDetails;
|
details?: ProviderHealthDetails;
|
||||||
|
|
@ -38,21 +38,44 @@ export const useProviderHealthQuery = (
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
async function checkProviderHealth(): Promise<ProviderHealthResponse> {
|
async function checkProviderHealth(): Promise<ProviderHealthResponse> {
|
||||||
const url = new URL("/api/provider/health", window.location.origin);
|
try {
|
||||||
|
const url = new URL("/api/provider/health", window.location.origin);
|
||||||
// Add provider query param if specified
|
|
||||||
if (params?.provider) {
|
|
||||||
url.searchParams.set("provider", params.provider);
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await fetch(url.toString());
|
// Add provider query param if specified
|
||||||
|
if (params?.provider) {
|
||||||
if (response.ok) {
|
url.searchParams.set("provider", params.provider);
|
||||||
return await response.json();
|
}
|
||||||
} else {
|
|
||||||
// For 400 and 503 errors, still parse JSON for error details
|
const response = await fetch(url.toString());
|
||||||
const errorData = await response.json().catch(() => ({}));
|
|
||||||
throw new Error(`${providerTitleMap[errorData.provider as ModelProvider] || "Provider"} error: ${errorData.message || "Failed to check provider health"}`);
|
if (response.ok) {
|
||||||
|
return await response.json();
|
||||||
|
} else if (response.status === 503) {
|
||||||
|
// Backend is up but provider validation failed
|
||||||
|
const errorData = await response.json().catch(() => ({}));
|
||||||
|
return {
|
||||||
|
status: "unhealthy",
|
||||||
|
message: errorData.message || "Provider validation failed",
|
||||||
|
provider: errorData.provider || params?.provider || "unknown",
|
||||||
|
details: errorData.details,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
// Other backend errors (400, etc.) - treat as provider issues
|
||||||
|
const errorData = await response.json().catch(() => ({}));
|
||||||
|
return {
|
||||||
|
status: "error",
|
||||||
|
message: errorData.message || "Failed to check provider health",
|
||||||
|
provider: errorData.provider || params?.provider || "unknown",
|
||||||
|
details: errorData.details,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
// Network error - backend is likely down, don't show provider banner
|
||||||
|
return {
|
||||||
|
status: "backend-unavailable",
|
||||||
|
message: error instanceof Error ? error.message : "Connection failed",
|
||||||
|
provider: params?.provider || "unknown",
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue