36 lines
513 B
Go
36 lines
513 B
Go
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
|
|
}
|