fixed ai image timeout
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
package com.krylov.refound.ai.client;
|
||||
|
||||
import com.krylov.refound.ai.exception.AiBadRequestException;
|
||||
import com.krylov.refound.ai.exception.AiException;
|
||||
import com.krylov.refound.ai.exception.AiServerException;
|
||||
import com.krylov.refound.ai.exception.AiTimeoutException;
|
||||
import com.krylov.refound.ai.exception.AiUnavailableException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatusCode;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
import org.springframework.web.reactive.function.client.WebClientRequestException;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@@ -39,13 +40,16 @@ public class AiHttpClient {
|
||||
|
||||
log.info("AI response received");
|
||||
return response;
|
||||
} catch (WebClientRequestException ex) {
|
||||
log.error("AI connection failed", ex);
|
||||
throw new AiUnavailableException(ex);
|
||||
|
||||
} catch (Exception ex) {
|
||||
log.error("AI request failed", ex);
|
||||
throw new AiUnavailableException(ex);
|
||||
AiException error = AiClientErrors.translate(ex);
|
||||
if (error instanceof AiTimeoutException) {
|
||||
log.warn("AI text moderation did not respond in time");
|
||||
} else if (error instanceof AiUnavailableException) {
|
||||
log.warn("AI text moderation is unavailable: {}", ex.getMessage());
|
||||
} else {
|
||||
log.warn("AI text moderation returned an error: {}", error.getMessage());
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user