Add more information to error output
This commit is contained in:
parent
a717c6ef38
commit
a3d3c170c9
@ -2,9 +2,14 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func errorName(err error) string {
|
||||
return reflect.ValueOf(err).Type().Name()
|
||||
}
|
||||
|
||||
// UserNameError is a base error for errors that deal with user names
|
||||
type UserNameError struct {
|
||||
Name string
|
||||
|
@ -119,14 +119,14 @@ func wsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if err != nil {
|
||||
switch err.(type) {
|
||||
case UserFormatError, UserTakenError:
|
||||
fmt.Printf("[handler] %v\n", err)
|
||||
fmt.Printf("[handler|%s] %v\n", errorName(err), err)
|
||||
case BannedUserError:
|
||||
fmt.Printf("[BAN] %v\n", err)
|
||||
fmt.Printf("[handler|%s] %v\n", errorName(err), err)
|
||||
// close connection since banned users shouldn't be connecting
|
||||
conn.Close()
|
||||
default:
|
||||
// for now all errors not caught need to be warned
|
||||
fmt.Printf("[handler] %v\n", err)
|
||||
fmt.Printf("[handler|uncaught] %v\n", err)
|
||||
conn.Close()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user