Enhance worker configuration and error handling for AI summarizer
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
- 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.
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package ai_summarizer
|
||||
|
||||
import "errors"
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Common sentinel errors for the AI summarizer package.
|
||||
var (
|
||||
@@ -37,3 +40,21 @@ var (
|
||||
// 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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user