feat: improve error handling
This commit is contained in:
parent
af9ab60092
commit
e6299c0010
4 changed files with 21 additions and 15 deletions
|
@ -83,15 +83,6 @@ func location(skip int) string {
|
|||
return fmt.Sprintf("%s:%d", file, line)
|
||||
}
|
||||
|
||||
var (
|
||||
ErrBadRole = errors.New("bad role")
|
||||
)
|
||||
|
||||
var (
|
||||
ErrBadTestingStrategy = errors.New("bad testing strategy")
|
||||
ErrBadResult = errors.New("bad result")
|
||||
)
|
||||
|
||||
type Error struct {
|
||||
src error
|
||||
layer layer
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package models
|
||||
|
||||
import "git.sch9.ru/new_gate/ms-tester/internal/lib"
|
||||
import (
|
||||
"errors"
|
||||
"git.sch9.ru/new_gate/ms-tester/internal/lib"
|
||||
)
|
||||
|
||||
type Result int32
|
||||
|
||||
|
@ -14,10 +17,12 @@ const (
|
|||
Testing Result = 6
|
||||
)
|
||||
|
||||
var ErrBadResult = errors.New("bad result")
|
||||
|
||||
func (result Result) Valid() error {
|
||||
switch result {
|
||||
case NotTested, Accepted, TimeLimitExceeded, MemoryLimitExceeded, CompilationError, SystemFailDuringTesting:
|
||||
return nil
|
||||
}
|
||||
return lib.ErrBadResult
|
||||
return lib.ServiceError(ErrBadResult, lib.ErrValidationFailed, "bad result")
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package models
|
||||
|
||||
import "git.sch9.ru/new_gate/ms-tester/internal/lib"
|
||||
import (
|
||||
"errors"
|
||||
"git.sch9.ru/new_gate/ms-tester/internal/lib"
|
||||
)
|
||||
|
||||
type Role int32
|
||||
|
||||
|
@ -35,12 +38,14 @@ func (role Role) AtMost(other Role) bool {
|
|||
return role <= other
|
||||
}
|
||||
|
||||
var ErrBadRole = errors.New("bad role")
|
||||
|
||||
func (role Role) Valid() error {
|
||||
switch role {
|
||||
case RoleSpectator, RoleParticipant, RoleModerator, RoleAdmin:
|
||||
return nil
|
||||
}
|
||||
return lib.ErrBadRole
|
||||
return lib.ServiceError(ErrBadRole, lib.ErrValidationFailed, "bad role")
|
||||
}
|
||||
|
||||
func (role Role) AsPointer() *Role {
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package models
|
||||
|
||||
import "git.sch9.ru/new_gate/ms-tester/internal/lib"
|
||||
import (
|
||||
"errors"
|
||||
"git.sch9.ru/new_gate/ms-tester/internal/lib"
|
||||
)
|
||||
|
||||
type TestingStrategy int32
|
||||
|
||||
|
@ -20,10 +23,12 @@ type TestGroupData struct {
|
|||
TestAmount int32
|
||||
}
|
||||
|
||||
var ErrBadTestingStrategy = errors.New("bad testing strategy")
|
||||
|
||||
func (ts TestingStrategy) Valid() error {
|
||||
switch ts {
|
||||
case EachTestTS, CompleteGroupTS:
|
||||
return nil
|
||||
}
|
||||
return lib.ErrBadTestingStrategy
|
||||
return lib.ServiceError(ErrBadTestingStrategy, lib.ErrValidationFailed, "bad testing strategy")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue