Enhance ApiStatusIndicator to conditionally render for aws-admin accounts only. Improve error handling in API response management across various components, ensuring expected 400 responses are logged appropriately. Update Credits and ApiMonitor components to handle null values gracefully and implement CRUD operations for planner and writer endpoints.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { useState, useEffect, useCallback, useRef } from "react";
|
||||
import { API_BASE_URL } from "../../services/api";
|
||||
import { useAuthStore } from "../../store/authStore";
|
||||
|
||||
interface GroupStatus {
|
||||
name: string;
|
||||
@@ -77,10 +78,19 @@ const endpointGroups = [
|
||||
];
|
||||
|
||||
export default function ApiStatusIndicator() {
|
||||
const { user } = useAuthStore();
|
||||
const [groupStatuses, setGroupStatuses] = useState<GroupStatus[]>([]);
|
||||
const [isChecking, setIsChecking] = useState(false);
|
||||
const intervalRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
|
||||
// Only show and run for aws-admin accounts
|
||||
const isAwsAdmin = user?.account?.slug === 'aws-admin';
|
||||
|
||||
// Return null if not aws-admin account
|
||||
if (!isAwsAdmin) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const checkEndpoint = useCallback(async (path: string, method: string): Promise<'healthy' | 'warning' | 'error'> => {
|
||||
try {
|
||||
const token = localStorage.getItem('auth_token') ||
|
||||
@@ -135,8 +145,22 @@ export default function ApiStatusIndicator() {
|
||||
fetchOptions.body = JSON.stringify(body);
|
||||
}
|
||||
|
||||
// Suppress console errors for expected 400 responses (validation errors from test data)
|
||||
// These are expected and indicate the endpoint is working
|
||||
const isExpected400 = method === 'POST' && (
|
||||
path.includes('/login/') ||
|
||||
path.includes('/register/') ||
|
||||
path.includes('/bulk_') ||
|
||||
path.includes('/test/')
|
||||
);
|
||||
|
||||
const response = await fetch(`${API_BASE_URL}${path}`, fetchOptions);
|
||||
|
||||
// Suppress console errors for expected 400 responses
|
||||
if (!isExpected400 || response.status !== 400) {
|
||||
// Only log if it's not an expected 400
|
||||
}
|
||||
|
||||
if (actualMethod === 'OPTIONS') {
|
||||
if (response.status === 200) {
|
||||
return 'healthy';
|
||||
@@ -158,7 +182,18 @@ export default function ApiStatusIndicator() {
|
||||
}
|
||||
return 'warning';
|
||||
} else if (method === 'POST') {
|
||||
// Suppress console errors for expected 400 responses (validation errors from test data)
|
||||
const isExpected400 = path.includes('/login/') ||
|
||||
path.includes('/register/') ||
|
||||
path.includes('/bulk_') ||
|
||||
path.includes('/test/');
|
||||
|
||||
if (response.status === 400) {
|
||||
// 400 is expected for test requests - endpoint is working
|
||||
if (!isExpected400) {
|
||||
// Only log if it's unexpected
|
||||
console.warn(`[ApiStatusIndicator] ${method} ${path}: 400 (unexpected)`);
|
||||
}
|
||||
return 'healthy';
|
||||
} else if (response.status >= 200 && response.status < 300) {
|
||||
return 'healthy';
|
||||
@@ -170,6 +205,19 @@ export default function ApiStatusIndicator() {
|
||||
return 'error';
|
||||
}
|
||||
return 'warning';
|
||||
} else if (method === 'PUT' || method === 'DELETE') {
|
||||
// UPDATE/DELETE operations
|
||||
if (response.status === 400 || response.status === 404) {
|
||||
// 400/404 expected for test requests - endpoint is working
|
||||
return 'healthy';
|
||||
} else if (response.status === 204 || (response.status >= 200 && response.status < 300)) {
|
||||
return 'healthy';
|
||||
} else if (response.status === 401 || response.status === 403) {
|
||||
return 'warning';
|
||||
} else if (response.status >= 500) {
|
||||
return 'error';
|
||||
}
|
||||
return 'warning';
|
||||
}
|
||||
|
||||
return 'warning';
|
||||
|
||||
Reference in New Issue
Block a user