fix: localize validation errors and polish delivery
Build and publish Docker images / Build and publish images (push) Failing after 25s
Build and publish Docker images / Build and publish images (push) Failing after 25s
This commit is contained in:
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user