Browse Source

Add more information to error output

master
joeyak 1 year ago
parent
commit
a3d3c170c9
2 changed files with 8 additions and 3 deletions
  1. +5
    -0
      errors.go
  2. +3
    -3
      handlers.go

+ 5
- 0
errors.go 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

+ 3
- 3
handlers.go 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()
}
}

Loading…
Cancel
Save