2019-10-12 04:46:21 -04:00
|
|
|
package common
|
2019-06-13 03:16:49 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
type NotFoundError struct {
|
|
|
|
message string
|
|
|
|
}
|
|
|
|
|
|
|
|
type ExpectedStateError struct {
|
|
|
|
message string
|
|
|
|
}
|
|
|
|
|
2019-10-24 05:10:48 -04:00
|
|
|
type NotCompletedError struct {
|
2019-06-13 03:16:49 -04:00
|
|
|
message string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *ExpectedStateError) Error() string {
|
|
|
|
return e.message
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *NotFoundError) Error() string {
|
|
|
|
return e.message
|
|
|
|
}
|
|
|
|
|
2019-10-24 05:10:48 -04:00
|
|
|
func (e *NotCompletedError) Error() string {
|
2019-06-13 03:16:49 -04:00
|
|
|
return e.message
|
|
|
|
}
|
|
|
|
|
2019-10-12 04:46:21 -04:00
|
|
|
func NewNotFoundError(product, id string) error {
|
2019-06-13 03:16:49 -04:00
|
|
|
return &NotFoundError{fmt.Sprintf("the %s %s is not found", product, id)}
|
|
|
|
}
|
|
|
|
|
2019-10-12 04:46:21 -04:00
|
|
|
func NewExpectedStateError(product, id string) error {
|
2019-06-13 03:16:49 -04:00
|
|
|
return &ExpectedStateError{fmt.Sprintf("the %s %s not be expected state", product, id)}
|
|
|
|
}
|
|
|
|
|
2019-10-24 05:10:48 -04:00
|
|
|
func NewNotCompletedError(product string) error {
|
|
|
|
return &NotCompletedError{fmt.Sprintf("%s is not completed", product)}
|
2019-06-13 03:16:49 -04:00
|
|
|
}
|
|
|
|
|
2019-10-12 04:46:21 -04:00
|
|
|
func IsNotFoundError(err error) bool {
|
2019-06-13 03:16:49 -04:00
|
|
|
if _, ok := err.(*NotFoundError); ok {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-10-12 04:46:21 -04:00
|
|
|
func IsExpectedStateError(err error) bool {
|
2019-06-13 03:16:49 -04:00
|
|
|
if _, ok := err.(*ExpectedStateError); ok {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-10-12 04:46:21 -04:00
|
|
|
func IsNotCompleteError(err error) bool {
|
2019-10-24 05:10:48 -04:00
|
|
|
if _, ok := err.(*NotCompletedError); ok {
|
2019-06-13 03:16:49 -04:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|