This commit is contained in:
Bel LaPointe
2021-03-13 15:59:07 -06:00
parent cb42bdc8d0
commit 4bf83b3e40
20 changed files with 267 additions and 13 deletions

35
src/consts/errors.go Normal file
View 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
}