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