Add more information to error output

This commit is contained in:
joeyak 2019-03-15 18:57:12 -04:00
parent a717c6ef38
commit a3d3c170c9
2 changed files with 8 additions and 3 deletions

View File

@ -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

View File

@ -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()
}
}