Files
Mazyar ca35eb5f15
continuous-integration/drone/push Build is passing
Enhance worker configuration and error handling for AI summarizer
- Added `TranslationEnabled` and `TranslationInterval` fields to the worker configuration to manage automatic translation scheduling.
- Updated the worker initialization to log when the translation worker is disabled.
- Improved error handling in the AI summarizer client by introducing `APIStatusError` for better context on API failures, replacing direct error messages with structured error responses.

This update enhances the configurability of the worker and improves error reporting for AI service interactions, contributing to better maintainability and user experience.
2026-06-14 14:02:35 +03:30

61 lines
2.2 KiB
Go

package ai_summarizer
import (
"errors"
"fmt"
)
// Common sentinel errors for the AI summarizer package.
var (
// ErrSummaryNotReady is returned when the tender.json exists but
// summarize_status.done is still false.
ErrSummaryNotReady = errors.New("ai_summarizer: summary not ready yet")
// ErrNoOverallSummary is returned when the pipeline is done but
// summary / overall_summary text is empty.
ErrNoOverallSummary = errors.New("ai_summarizer: tender summary is empty")
// ErrTranslationNotReady is returned when tender.json exists but the
// requested language is not listed in translation_status.done yet.
ErrTranslationNotReady = errors.New("ai_summarizer: translation not ready yet")
// ErrNoTranslation is returned when translation_status marks a language done
// but translations[language] is missing or empty.
ErrNoTranslation = errors.New("ai_summarizer: translation is empty")
// ErrObjectNotFound is returned when the tender.json object does not
// exist in the MinIO bucket (HTTP 404 / NoSuchKey).
ErrObjectNotFound = errors.New("ai_summarizer: tender.json not found in storage")
// ErrBucketNotFound is returned when the MinIO bucket does not exist.
ErrBucketNotFound = errors.New("ai_summarizer: bucket not found")
// ErrMinIOUnavailable is returned when MinIO cannot be reached (network,
// timeout, connection refused, etc.) as opposed to a missing object key.
ErrMinIOUnavailable = errors.New("ai_summarizer: MinIO connection unavailable")
// ErrAPINonSuccess is returned when the AI API returns a non-2xx status code.
ErrAPINonSuccess = errors.New("ai_summarizer: API returned non-success status")
// ErrPipelineJobRunning is returned when a single-flight pipeline job is already running (HTTP 409).
ErrPipelineJobRunning = errors.New("ai_summarizer: pipeline job already running")
)
// APIStatusError carries the HTTP status and response body from the Opplens AI service.
type APIStatusError struct {
StatusCode int
Body string
}
func (e *APIStatusError) Error() string {
if e == nil {
return ""
}
return fmt.Sprintf("ai_summarizer: API returned status %d, body: %s", e.StatusCode, e.Body)
}
// Is reports whether target is ErrAPINonSuccess.
func (e *APIStatusError) Is(target error) bool {
return target == ErrAPINonSuccess
}