Ver código fonte

Prevent login crash by assuming a json.Unmarshal "just works"

Seth Moore 9 anos atrás
pai
commit
2d7ac3557a
1 arquivos alterados com 4 adições e 0 exclusões
  1. 4 0
      restapi.go

+ 4 - 0
restapi.go

@@ -111,6 +111,10 @@ func (s *Session) Login(email string, password string) (token string, err error)
 
 	var temp map[string]interface{}
 	err = json.Unmarshal(response, &temp)
+	// prevent crashing by manipulating a map that has no data
+	if err != nil {
+		return
+	}
 	token = temp["token"].(string)
 	return
 }