Implement a new endpoint to check CITES API connectivity using a dedicated API call instead of token validation.
Replit-Commit-Author: Agent Replit-Commit-Session-Id: e931b5ab-041b-42e7-baf1-50017869cef6 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/e19c6a51-7e4c-4bb8-a6a6-46dc00f0ec99/2b0086f8-9e7d-4ae1-adc4-d84a54cd21ff.jpg
This commit is contained in:
@ -177,13 +177,8 @@ export const apiClient = {
|
||||
|
||||
async checkCitesApiStatus(): Promise<ApiStatusResponse> {
|
||||
try {
|
||||
// We'll use the token endpoint to check if the CITES API is accessible
|
||||
const token = await this.getToken();
|
||||
return {
|
||||
success: true,
|
||||
connected: !!token,
|
||||
message: token ? "CITES API is connected" : "CITES API token not found"
|
||||
};
|
||||
const response = await axios.get<ApiStatusResponse>("/api/cites/status");
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
return {
|
||||
success: false,
|
||||
|
@ -213,6 +213,56 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
||||
}
|
||||
});
|
||||
|
||||
// CITES API Status check endpoint
|
||||
app.get("/api/cites/status", async (req: Request, res: Response) => {
|
||||
try {
|
||||
const activeToken = await storage.getActiveToken();
|
||||
|
||||
if (!activeToken || !activeToken.token) {
|
||||
return res.status(401).json({
|
||||
success: false,
|
||||
connected: false,
|
||||
message: "CITES API token is not configured"
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
// Make a request to the CITES API to verify the token
|
||||
const response = await axios.get(`${CITES_BASE_URL}/taxon_concepts/search`, {
|
||||
params: {
|
||||
page: 1,
|
||||
per_page: 1
|
||||
},
|
||||
headers: {
|
||||
'X-Authentication-Token': activeToken.token
|
||||
}
|
||||
});
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
connected: true,
|
||||
message: "CITES API is connected and responding"
|
||||
});
|
||||
} catch (error) {
|
||||
if (axios.isAxiosError(error) && error.response) {
|
||||
return res.status(error.response.status).json({
|
||||
success: false,
|
||||
connected: false,
|
||||
message: "Failed to connect to CITES API or invalid token",
|
||||
status: error.response.status
|
||||
});
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
connected: false,
|
||||
message: "Error checking CITES API status"
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// IUCN API Status check endpoint
|
||||
app.get("/api/iucn/status", async (req: Request, res: Response) => {
|
||||
try {
|
||||
@ -220,13 +270,14 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
||||
if (!apiKey) {
|
||||
return res.status(401).json({
|
||||
success: false,
|
||||
connected: false,
|
||||
message: "IUCN API key is not configured"
|
||||
});
|
||||
}
|
||||
|
||||
// Use a region endpoint which is simpler and less prone to errors
|
||||
// Use the version endpoint which is the simplest endpoint
|
||||
try {
|
||||
const response = await axios.get(`${IUCN_BASE_URL}/region/list`, {
|
||||
const response = await axios.get(`${IUCN_BASE_URL}/version`, {
|
||||
params: { token: apiKey }
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user