encoding/json panic recovery
This commit is contained in:
parent
1f0997054e
commit
1f2f313d47
10
send.go
10
send.go
|
@ -3,8 +3,9 @@ package gosocketio
|
|||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"time"
|
||||
"github.com/graarh/golang-socketio/protocol"
|
||||
"log"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -16,6 +17,13 @@ var (
|
|||
Send message packet to socket
|
||||
*/
|
||||
func send(msg *protocol.Message, c *Channel, args interface{}) error {
|
||||
//preventing json/encoding "index out of range" panic
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
log.Println("socket.io send panic: ", r)
|
||||
}
|
||||
}()
|
||||
|
||||
if args != nil {
|
||||
json, err := json.Marshal(&args)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue