make sure panics don't slip out of websockets

This commit is contained in:
Morgan Bazalgette 2017-04-18 21:13:31 +02:00
parent 330b90b172
commit ace4c6bee0
No known key found for this signature in database
GPG Key ID: 40D328300D245DA5
2 changed files with 10 additions and 0 deletions

View File

@ -12,6 +12,7 @@ import (
var stepNumber uint64
func handler(rawConn *websocket.Conn) {
defer catchPanic()
defer rawConn.Close()
step := atomic.AddUint64(&stepNumber, 1)

View File

@ -75,6 +75,7 @@ type score struct {
}
func handleNewScore(id string) {
defer catchPanic()
var s score
err := db.Get(&s, `
SELECT
@ -131,3 +132,11 @@ func inModes(modes []int, i int) bool {
}
return false
}
func catchPanic() {
r := recover()
if r != nil {
fmt.Println(r)
// TODO: sentry
}
}