Files
mangezmieux/mangezmieux-backend/internal/postgres/database_error.go
2024-07-19 17:04:42 +02:00

33 lines
457 B
Go
Executable File

package postgres
import (
"fmt"
)
type Type int
const (
ErrTypeNotFound Type = iota
ErrTypeDuplicate
ErrTypeForeignKeyViolation
)
type Error struct {
Cause error
Type Type
}
func NewDAOError(t Type, cause error) error {
return &Error{
Type: t,
Cause: cause,
}
}
func (e *Error) Error() string {
if e.Cause != nil {
return fmt.Sprintf("Type %d: %s", e.Type, e.Cause.Error())
}
return fmt.Sprintf("Type %d: no cause given", e.Type)
}