fix: localize validation errors and polish delivery
Build and publish Docker images / Build and publish images (push) Failing after 25s

This commit is contained in:
2026-09-15 16:28:02 +08:00
parent f79c80519d
commit dc5ace9003
10 changed files with 421 additions and 14 deletions
@@ -17,6 +17,7 @@ import (
"github.com/gochat/gochat/internal/service"
"github.com/gochat/gochat/pkg/pagination"
"github.com/gochat/gochat/pkg/response"
pkgvalidator "github.com/gochat/gochat/pkg/validator"
"gorm.io/datatypes"
)
@@ -1159,6 +1160,10 @@ func handleServiceError(c *gin.Context, err error) {
if err == nil {
return
}
if pkgvalidator.IsValidationError(err) {
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrValidation, pkgvalidator.ValidationMessage(err))
return
}
errMsg := err.Error()
if errors.Is(err, service.ErrCaptainAssistantDisabled) {
response.AbortWithStatusError(c, http.StatusConflict, response.ErrCaptainAssistantDisabled, errMsg)
@@ -18,6 +18,7 @@ import (
"github.com/gochat/gochat/internal/service"
"github.com/gochat/gochat/pkg/pagination"
"github.com/gochat/gochat/pkg/response"
pkgvalidator "github.com/gochat/gochat/pkg/validator"
"gorm.io/datatypes"
)
@@ -388,6 +389,10 @@ func (h *MessageHandler) Translate(c *gin.Context) {
}
result, svcErr := h.svc.TranslateInConversation(c.Request.Context(), accountID, conversation.ID, messageID, req)
if svcErr != nil {
if pkgvalidator.IsValidationError(svcErr) {
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrValidation, pkgvalidator.ValidationMessage(svcErr))
return
}
lower := strings.ToLower(svcErr.Error())
if strings.Contains(lower, "not found") {
response.AbortWithStatusError(c, http.StatusNotFound, response.ErrNotFound, svcErr.Error())