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,15 @@
package errors
type AlreadyExistsError struct {
msg string
}
func NewAlreadyExistsError(msg string) *AlreadyExistsError {
return &AlreadyExistsError{
msg: msg,
}
}
func (e *AlreadyExistsError) Error() string {
return "Already exists: " + e.msg
}

View file

@ -4,12 +4,12 @@ type DBError struct {
msg string
}
func NewDBError(msg string) DBError {
return DBError{
func NewDBError(msg string) *DBError {
return &DBError{
msg: msg,
}
}
func (e *DBError) Error() string {
return e.msg
return "Database error:" + e.msg
}

View file

@ -11,5 +11,5 @@ func NewNotFoundError(msg string) *NotFoundError {
}
func (e *NotFoundError) Error() string {
return e.msg
return "Not found error: " + e.msg
}

View file

@ -0,0 +1,15 @@
package errors
type ValidationError struct {
msg string
}
func NewValidationError(msg string) *ValidationError {
return &ValidationError{
msg: msg,
}
}
func (e *ValidationError) Error() string {
return "Validation error: " + e.msg
}