Enhance worker configuration and error handling for AI summarizer
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:
Mazyar
2026-06-14 14:02:35 +03:30
parent 42d64c4ec6
commit ca35eb5f15
5 changed files with 89 additions and 22 deletions
+34 -4
View File
@@ -2,6 +2,7 @@ package ai_pipeline
import (
"errors"
"fmt"
"net/http"
"tm/pkg/ai_summarizer"
@@ -389,13 +390,42 @@ func mapPipelineHTTPError(c echo.Context, err error, action string) error {
return response.Conflict(c, "A pipeline job is already running")
case errors.Is(err, ai_summarizer.ErrObjectNotFound):
return response.NotFound(c, "Tender not found in AI service")
default:
if errors.Is(err, ai_summarizer.ErrAPINonSuccess) {
}
var upstream *ai_summarizer.APIStatusError
if errors.As(err, &upstream) {
details := upstream.Body
if details == "" {
details = fmt.Sprintf("upstream status %d", upstream.StatusCode)
}
switch upstream.StatusCode {
case http.StatusNotFound:
return response.NotFound(c, "Tender not found in AI service")
case http.StatusUnprocessableEntity:
return response.ValidationError(c, "AI service rejected the request", details)
case http.StatusBadGateway:
return c.JSON(http.StatusBadGateway, response.APIResponse{
Success: false,
Message: action + " failed: upstream AI service error",
Message: action + " failed",
Error: &response.APIError{
Code: "UPSTREAM_AI_ERROR",
Message: "Opplens AI service returned status 502",
Details: details,
},
})
default:
return c.JSON(http.StatusBadGateway, response.APIResponse{
Success: false,
Message: action + " failed",
Error: &response.APIError{
Code: "UPSTREAM_AI_ERROR",
Message: fmt.Sprintf("Opplens AI service returned status %d", upstream.StatusCode),
Details: details,
},
})
}
return response.InternalServerError(c, action+" failed")
}
return response.InternalServerError(c, action+" failed")
}