src.dualinventive.com/go/users-service/errors/errors.go

77 lines
1.9 KiB
Go

package errors
import "fmt"
//ErrUserNotFound occurs when a user is not found.
type ErrUserNotFound struct{}
//Error returns error message
func (e *ErrUserNotFound) Error() string {
return "user not found"
}
//NewErrUserNotFound occurs when a user is not found.
func NewErrUserNotFound() error {
return &ErrUserNotFound{}
}
//ErrInvalidArgument occurs when an argument is invalid.
type ErrInvalidArgument struct {
argument string
message string
}
//Error returns error message
func (e *ErrInvalidArgument) Error() string {
return fmt.Sprintf("invalid argument: %s (%s)", e.argument, e.message)
}
//NewErrInvalidArgument occurs when an argument is invalid.
func NewErrInvalidArgument(argument string, message string) error {
return &ErrInvalidArgument{argument, message}
}
//ErrUserRepositoryErr occurs when something in the user repository went wrong.
type ErrUserRepositoryErr struct {
message string
original error
}
//Error returns error message
func (e *ErrUserRepositoryErr) Error() string {
return fmt.Sprintf("%s: %s", e.message, e.original.Error())
}
//NewErrUserRepositoryErr occurs when something in the user repository went wrong.
func NewErrUserRepositoryErr(message string, original error) error {
return &ErrUserRepositoryErr{message, original}
}
//ErrAuthFailed occurs when something in the auth client went wrong.
type ErrAuthFailed struct {
original error
}
//Error returns error message
func (e *ErrAuthFailed) Error() string {
return fmt.Sprintf("authentication failed: %s", e.original.Error())
}
//NewErrAuthFailed occurs when something in the auth client went wrong.
func NewErrAuthFailed(original error) error {
return &ErrAuthFailed{original}
}
//ErrUnauthorized occurs when a user is not found.
type ErrUnauthorized struct{}
//Error returns error message
func (e *ErrUnauthorized) Error() string {
return "unauthorized"
}
//NewErrUnauthorized occurs when a user is not found.
func NewErrUnauthorized() error {
return &ErrUnauthorized{}
}