Browse Source

Add more information to error output

pull/1/head
joeyak 3 years ago
parent
commit
a3d3c170c9
  1. 5
      errors.go
  2. 6
      handlers.go

5
errors.go

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

6
handlers.go

@ -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…
Cancel
Save