make application with base logic
This commit is contained in:
36
internal/common/errors/error.go
Normal file
36
internal/common/errors/error.go
Normal file
@ -0,0 +1,36 @@
|
||||
package errors
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
const (
|
||||
ErrNotImplemented SimpleError = "not implemented"
|
||||
ErrUnexpectedStatus SimpleError = "unexpected status"
|
||||
)
|
||||
|
||||
type SimpleError string
|
||||
|
||||
func (err SimpleError) Error() string {
|
||||
return string(err)
|
||||
}
|
||||
|
||||
type ValidationError struct {
|
||||
Field string
|
||||
Reason string
|
||||
}
|
||||
|
||||
func (err *ValidationError) Error() string {
|
||||
return fmt.Sprintf("field %s is not valid for reason %s", err.Field, err.Reason)
|
||||
}
|
||||
|
||||
func NewValidationError(field, reason string) *ValidationError {
|
||||
if field == "" {
|
||||
panic("field not provided")
|
||||
}
|
||||
|
||||
return &ValidationError{
|
||||
Field: field,
|
||||
Reason: reason,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user