Ver Fonte

Merge pull request #171 from iopred/develop

Fix unmarshall error with Invite, improve error logging.
Bruce há 8 anos atrás
pai
commit
b14a2ce8da
3 ficheiros alterados com 10 adições e 9 exclusões
  1. 4 4
      restapi.go
  2. 1 1
      structs.go
  3. 5 4
      wsapi.go

+ 4 - 4
restapi.go

@@ -1108,10 +1108,10 @@ func (s *Session) ChannelInvites(channelID string) (st []*Invite, err error) {
 func (s *Session) ChannelInviteCreate(channelID string, i Invite) (st *Invite, err error) {
 
 	data := struct {
-		MaxAge    int  `json:"max_age"`
-		MaxUses   int  `json:"max_uses"`
-		Temporary bool `json:"temporary"`
-		XKCDPass  bool `json:"xkcdpass"`
+		MaxAge    int    `json:"max_age"`
+		MaxUses   int    `json:"max_uses"`
+		Temporary bool   `json:"temporary"`
+		XKCDPass  string `json:"xkcdpass"`
 	}{i.MaxAge, i.MaxUses, i.Temporary, i.XkcdPass}
 
 	body, err := s.Request("POST", CHANNEL_INVITES(channelID), data)

+ 1 - 1
structs.go

@@ -111,7 +111,7 @@ type Invite struct {
 	MaxAge    int      `json:"max_age"`
 	Uses      int      `json:"uses"`
 	MaxUses   int      `json:"max_uses"`
-	XkcdPass  bool     `json:"xkcdpass"`
+	XkcdPass  string   `json:"xkcdpass"`
 	Revoked   bool     `json:"revoked"`
 	Temporary bool     `json:"temporary"`
 }

+ 5 - 4
wsapi.go

@@ -15,6 +15,7 @@ import (
 	"compress/zlib"
 	"encoding/json"
 	"errors"
+	"fmt"
 	"io"
 	"log"
 	"net/http"
@@ -270,7 +271,7 @@ func (s *Session) event(messageType int, message []byte) {
 	if messageType == 2 {
 		z, err1 := zlib.NewReader(reader)
 		if err1 != nil {
-			log.Println(err1)
+			log.Println(fmt.Sprintf("Error uncompressing message type %d: %s", messageType, err1))
 			return
 		}
 		defer func() {
@@ -285,7 +286,7 @@ func (s *Session) event(messageType int, message []byte) {
 	var e *Event
 	decoder := json.NewDecoder(reader)
 	if err = decoder.Decode(&e); err != nil {
-		log.Println(err)
+		log.Println(fmt.Sprintf("Error decoding message type %d: %s", messageType, err))
 		return
 	}
 
@@ -300,8 +301,8 @@ func (s *Session) event(messageType int, message []byte) {
 
 		// Attempt to unmarshal our event.
 		// If there is an error we should handle the event itself.
-		if err = unmarshal(e.RawData, i); err != nil {
-			log.Println("Unable to unmarshal event data.", err)
+		if err = json.Unmarshal(e.RawData, i); err != nil {
+			log.Println(fmt.Sprintf("Unable to unmarshal event %s data: %s", e.Type, err))
 			// Ready events must fire, even if they are empty.
 			if e.Type != "READY" {
 				i = nil