// ParseErrors Parser of error string messages returns RestError
ParseErrors Parser of error string messages returns RestError
// ParseErrors Parser of error string messages returns RestError
func ParseErrors(err error, debug bool) RestErr {
	switch {
	case errors.Is(err, sql.ErrNoRows):
		return NewRestError(http.StatusNotFound, ErrNotFound, err.Error(), debug)
	case errors.Is(err, context.DeadlineExceeded):
		return NewRestError(http.StatusRequestTimeout, ErrRequestTimeout, err.Error(), debug)
	case errors.Is(err, Unauthorized):
		return NewRestError(http.StatusUnauthorized, ErrUnauthorized, err.Error(), debug)
	case errors.Is(err, WrongCredentials):
		return NewRestError(http.StatusUnauthorized, ErrUnauthorized, err.Error(), debug)
	case strings.Contains(strings.ToLower(err.Error()), "sqlstate"):
		return parseSqlErrors(err, debug)
	case strings.Contains(strings.ToLower(err.Error()), "field validation"):
		if validationErrors, ok := err.(validator.ValidationErrors); ok {
			return NewRestError(http.StatusBadRequest, ErrBadRequest, validationErrors.Error(), debug)
		}
		return parseValidatorError(err, debug)
	case strings.Contains(strings.ToLower(err.Error()), "required header"):
		return NewRestError(http.StatusBadRequest, ErrBadRequest, err.Error(), debug)
	case strings.Contains(strings.ToLower(err.Error()), "base64"):
		return NewRestError(http.StatusBadRequest, ErrBadRequest, err.Error(), debug)
	case strings.Contains(strings.ToLower(err.Error()), "unmarshal"):
		return NewRestError(http.StatusBadRequest, ErrBadRequest, err.Error(), debug)
	case strings.Contains(strings.ToLower(err.Error()), "uuid"):
		return NewRestError(http.StatusBadRequest, ErrBadRequest, err.Error(), debug)
	case strings.Contains(strings.ToLower(err.Error()), "cookie"):
		return NewRestError(http.StatusUnauthorized, ErrUnauthorized, err.Error(), debug)
	case strings.Contains(strings.ToLower(err.Error()), "token"):
		return NewRestError(http.StatusUnauthorized, ErrUnauthorized, err.Error(), debug)
	case strings.Contains(strings.ToLower(err.Error()), "bcrypt"):
		return NewRestError(http.StatusBadRequest, ErrBadRequest, err.Error(), debug)
	case strings.Contains(strings.ToLower(err.Error()), "no documents in result"):
		return NewRestError(http.StatusNotFound, ErrNotFound, err.Error(), debug)
	default:
		if restErr, ok := err.(*RestError); ok {
			return restErr
		}
		return NewRestError(http.StatusInternalServerError, ErrInternalServerError, errors.Cause(err).Error(), debug)
	}
}
func ParseErrors ( err error , debug bool ) RestErr { switch { case errors . Is ( err , sql . ErrNoRows ) : return NewRestError ( http . StatusNotFound , ErrNotFound , err . Error ( ) , debug ) case errors . Is ( err , context . DeadlineExceeded ) : return NewRestError ( http . StatusRequestTimeout , ErrRequestTimeout , err . Error ( ) , debug ) case errors . Is ( err , Unauthorized ) : return NewRestError ( http . StatusUnauthorized , ErrUnauthorized , err . Error ( ) , debug ) case errors . Is ( err , WrongCredentials ) : return NewRestError ( http . StatusUnauthorized , ErrUnauthorized , err . Error ( ) , debug ) case strings . Contains ( strings . ToLower ( err . Error ( ) ) , " " ) : return parseSqlErrors ( err , debug ) case strings . Contains ( strings . ToLower ( err . Error ( ) ) , " " ) : if validationErrors , ok := err . ( validator . ValidationErrors ) ; ok { return NewRestError ( http . StatusBadRequest , ErrBadRequest , validationErrors . Error ( ) , debug ) } return parseValidatorError ( err , debug ) case strings . Contains ( strings . ToLower ( err . Error ( ) ) , " " ) : return NewRestError ( http . StatusBadRequest , ErrBadRequest , err . Error ( ) , debug ) case strings . Contains ( strings . ToLower ( err . Error ( ) ) , " " ) : return NewRestError ( http . StatusBadRequest , ErrBadRequest , err . Error ( ) , debug ) case strings . Contains ( strings . ToLower ( err . Error ( ) ) , " " ) : return NewRestError ( http . StatusBadRequest , ErrBadRequest , err . Error ( ) , debug ) case strings . Contains ( strings . ToLower ( err . Error ( ) ) , " " ) : return NewRestError ( http . StatusBadRequest , ErrBadRequest , err . Error ( ) , debug ) case strings . Contains ( strings . ToLower ( err . Error ( ) ) , " " ) : return NewRestError ( http . StatusUnauthorized , ErrUnauthorized , err . Error ( ) , debug ) case strings . Contains ( strings . ToLower ( err . Error ( ) ) , " " ) : return NewRestError ( http . StatusUnauthorized , ErrUnauthorized , err . Error ( ) , debug ) case strings . Contains ( strings . ToLower ( err . Error ( ) ) , " " ) : return NewRestError ( http . StatusBadRequest , ErrBadRequest , err . Error ( ) , debug ) case strings . Contains ( strings . ToLower ( err . Error ( ) ) , " " ) : return NewRestError ( http . StatusNotFound , ErrNotFound , err . Error ( ) , debug ) default : if restErr , ok := err . ( * RestError ) ; ok { return restErr } return NewRestError ( http . StatusInternalServerError , ErrInternalServerError , errors . Cause ( err ) . Error ( ) , debug ) } }
ParseErrors Parser of error string messages returns RestError
ParseErrors Parser of error string messages returns RestError