fix: parse moderation api response after checking if response is ok
should fix long wait times for an error code when moderation api is down
This commit is contained in:
parent
ddc7cd92d2
commit
08861f8d75
1 changed files with 2 additions and 2 deletions
|
|
@ -45,13 +45,13 @@ export async function validateImage(file: File): Promise<{ valid: boolean; error
|
||||||
formData.append("image", blob);
|
formData.append("image", blob);
|
||||||
|
|
||||||
const moderationResponse = await fetch("https://api.trafficlunar.net/moderate/image", { method: "POST", body: formData });
|
const moderationResponse = await fetch("https://api.trafficlunar.net/moderate/image", { method: "POST", body: formData });
|
||||||
const result = await moderationResponse.json();
|
|
||||||
|
|
||||||
if (!moderationResponse.ok) {
|
if (!moderationResponse.ok) {
|
||||||
console.error("Moderation API error:", result);
|
console.error("Moderation API error");
|
||||||
return { valid: false, error: "Content moderation check failed", status: 500 };
|
return { valid: false, error: "Content moderation check failed", status: 500 };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const result = await moderationResponse.json();
|
||||||
if (result.error) {
|
if (result.error) {
|
||||||
return { valid: false, error: result.error };
|
return { valid: false, error: result.error };
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue