reorg
This commit is contained in:
35
src/consts/errors.go
Normal file
35
src/consts/errors.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package consts
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrGameExists = NewCodeError("game exists", http.StatusConflict)
|
||||
)
|
||||
|
||||
type CodeError struct {
|
||||
Err string
|
||||
Status int
|
||||
}
|
||||
|
||||
func NewCodeError(err string, status int) CodeError {
|
||||
return CodeError{
|
||||
Err: err,
|
||||
Status: status,
|
||||
}
|
||||
}
|
||||
|
||||
func (ce CodeError) Error() string {
|
||||
if ce.Err == "" {
|
||||
return "unspecified error occurred"
|
||||
}
|
||||
return ce.Err
|
||||
}
|
||||
|
||||
func (ce CodeError) Code() int {
|
||||
if ce.Status == 0 {
|
||||
return http.StatusInternalServerError
|
||||
}
|
||||
return ce.Status
|
||||
}
|
||||
Reference in New Issue
Block a user