feat: status api
This commit is contained in:
@@ -5,10 +5,13 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
ErrDummy int = -1
|
||||
ErrStorageFailure int = 1000 + iota
|
||||
ErrGameNotInitialized
|
||||
ErrGameStateInvalid
|
||||
)
|
||||
|
||||
ErrStorageFailure int = 1000
|
||||
ErrGameStateInvalid int = 2000
|
||||
const (
|
||||
ErrDummy int = -1
|
||||
|
||||
ErrDeleteShipTypeExistingGroup = 5000
|
||||
ErrDeleteShipTypePlanetProduction = 5001
|
||||
@@ -68,6 +71,8 @@ func GenericErrorText(code int) string {
|
||||
return "Dummy"
|
||||
case ErrStorageFailure:
|
||||
return "Storage failure"
|
||||
case ErrGameNotInitialized:
|
||||
return "Game not yet initialized"
|
||||
case ErrGameStateInvalid:
|
||||
return "Invalid game state"
|
||||
case ErrInputUnknownRace:
|
||||
@@ -170,13 +175,13 @@ func GenericErrorText(code int) string {
|
||||
}
|
||||
|
||||
type GenericError struct {
|
||||
code int
|
||||
Code int
|
||||
subject string
|
||||
err error
|
||||
}
|
||||
|
||||
func (ge GenericError) Error() string {
|
||||
msg := GenericErrorText(ge.code)
|
||||
msg := GenericErrorText(ge.Code)
|
||||
if ge.subject != "" {
|
||||
msg += ": " + ge.subject
|
||||
}
|
||||
@@ -187,7 +192,7 @@ func (ge GenericError) Error() string {
|
||||
}
|
||||
|
||||
func newGenericError(code int, arg ...any) error {
|
||||
e := &GenericError{code: code}
|
||||
e := &GenericError{Code: code}
|
||||
if len(arg) > 0 {
|
||||
i := 0
|
||||
switch arg[i].(type) {
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package error
|
||||
|
||||
func NewGameNotInitializedError(arg ...any) error {
|
||||
return newGenericError(ErrGameNotInitialized, arg...)
|
||||
}
|
||||
|
||||
func NewGameStateError(arg ...any) error {
|
||||
return newGenericError(ErrGameStateInvalid, arg...)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user