src.dualinventive.com/go/companies-service/internal/companies/errors.go

77 lines
2.0 KiB
Go

package companies
import "fmt"
//ErrCompanyNotFound occurs when a company is not found.
type ErrCompanyNotFound struct{}
//Error returns error message
func (e *ErrCompanyNotFound) Error() string {
return "company not found"
}
//NewErrCompanyNotFound occurs when a company is not found.
func NewErrCompanyNotFound() error {
return &ErrCompanyNotFound{}
}
//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}
}
//ErrCompanyRepositoryErr occurs when something in the company repository went wrong.
type ErrCompanyRepositoryErr struct {
message string
original error
}
//Error returns error message
func (e *ErrCompanyRepositoryErr) Error() string {
return fmt.Sprintf("%s: %s", e.message, e.original.Error())
}
//NewErrCompanyRepositoryErr occurs when something in the company repository went wrong.
func NewErrCompanyRepositoryErr(message string, original error) error {
return &ErrCompanyRepositoryErr{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{}
}