eeafe2a625
continuous-integration/drone/push Build is passing
- Introduced InvalidStatusTransitionError to handle invalid status transitions for inquiries, providing clearer error messages. - Updated UpdateInquiryStatusForm to make the Reason field optional and added logic to set a default reason if not provided. - Enhanced form validation tests to cover new status transition error scenarios and validation messages. - Refactored handler methods to utilize new error handling functions for improved response management. This update improves the robustness of inquiry status management by ensuring proper error handling and validation, enhancing user experience during status updates.
39 lines
913 B
Go
39 lines
913 B
Go
package inquiry
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
|
|
"tm/pkg/response"
|
|
|
|
"github.com/labstack/echo/v4"
|
|
)
|
|
|
|
func handleBindError(c echo.Context, err error) error {
|
|
return response.BadRequest(c, "Invalid request format", err.Error())
|
|
}
|
|
|
|
func handleValidationError(c echo.Context, err error) error {
|
|
return response.ValidationError(c, "Please fix the validation errors", FormatValidationErrors(err))
|
|
}
|
|
|
|
func handleServiceError(c echo.Context, err error, fallback string) error {
|
|
if err == nil {
|
|
return nil
|
|
}
|
|
if errors.Is(err, ErrInquiryNotFound) {
|
|
return response.NotFound(c, "Inquiry not found")
|
|
}
|
|
|
|
var transitionErr *InvalidStatusTransitionError
|
|
if errors.As(err, &transitionErr) {
|
|
return response.BadRequest(c, transitionErr.Error(), "")
|
|
}
|
|
|
|
if strings.Contains(err.Error(), "cannot be updated") {
|
|
return response.BadRequest(c, err.Error(), "")
|
|
}
|
|
|
|
return response.InternalServerError(c, fallback)
|
|
}
|