Added errors for services

This commit is contained in:
KamilM1205 2025-09-23 22:03:00 +04:00
parent ab4b53fd40
commit c3c3d65d32
12 changed files with 217 additions and 86 deletions

View file

@ -0,0 +1,30 @@
package utils
import (
ie "58team_blog/internal/application/errors"
"58team_blog/internal/interfaces/api/responses"
"errors"
"log"
"net/http"
)
func HandleError(err error) responses.ErrorResponse {
var errorCode int
errorMsg := err.Error()
log.Println(err)
if errors.Is(&ie.ValidationError{}, err) {
errorCode = http.StatusBadRequest
} else if errors.Is(&ie.NotFoundError{}, err) {
errorCode = http.StatusNotFound
} else if errors.Is(&ie.AlreadyExistsError{}, err) {
errorCode = http.StatusConflict
} else if errors.Is(&ie.DBError{}, err) {
errorCode = http.StatusInternalServerError
} else {
errorCode = http.StatusInternalServerError
}
return responses.CreateErrorResponse(errorCode, errorMsg)
}