Don't panic if fetching web version fails
This commit is contained in:
parent
f6712be804
commit
52a703c94d
2 changed files with 17 additions and 13 deletions
|
@ -89,7 +89,10 @@ func NewClient(authData *AuthData, logger zerolog.Logger) *Client {
|
||||||
pingShortCircuit: make(chan struct{}),
|
pingShortCircuit: make(chan struct{}),
|
||||||
}
|
}
|
||||||
sessionHandler.client = cli
|
sessionHandler.client = cli
|
||||||
cli.FetchConfigVersion()
|
err := cli.FetchConfigVersion()
|
||||||
|
if err != nil {
|
||||||
|
cli.Logger.Warn().Err(err).Msg("Failed to fetch latest web version")
|
||||||
|
}
|
||||||
return cli
|
return cli
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,25 +200,25 @@ func (c *Client) triggerEvent(evt interface{}) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) FetchConfigVersion() {
|
func (c *Client) FetchConfigVersion() error {
|
||||||
req, bErr := http.NewRequest("GET", util.ConfigUrl, nil)
|
req, err := http.NewRequest(http.MethodGet, util.ConfigURL, nil)
|
||||||
if bErr != nil {
|
if err != nil {
|
||||||
panic(bErr)
|
return fmt.Errorf("failed to prepare request: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
configRes, requestErr := c.http.Do(req)
|
configRes, err := c.http.Do(req)
|
||||||
if requestErr != nil {
|
if err != nil {
|
||||||
panic(requestErr)
|
return fmt.Errorf("failed to send request: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
responseBody, readErr := io.ReadAll(configRes.Body)
|
responseBody, err := io.ReadAll(configRes.Body)
|
||||||
if readErr != nil {
|
if err != nil {
|
||||||
panic(readErr)
|
return fmt.Errorf("failed to read response body: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
version, parseErr := util.ParseConfigVersion(responseBody)
|
version, parseErr := util.ParseConfigVersion(responseBody)
|
||||||
if parseErr != nil {
|
if parseErr != nil {
|
||||||
panic(parseErr)
|
return fmt.Errorf("failed to parse response body: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
currVersion := util.ConfigMessage
|
currVersion := util.ConfigMessage
|
||||||
|
@ -225,6 +228,7 @@ func (c *Client) FetchConfigVersion() {
|
||||||
} else {
|
} else {
|
||||||
c.Logger.Debug().Any("version", currVersion).Msg("Using latest messages for web version")
|
c.Logger.Debug().Any("version", currVersion).Msg("Using latest messages for web version")
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) diffVersionFormat(curr *gmproto.ConfigVersion, latest *gmproto.ConfigVersion) string {
|
func (c *Client) diffVersionFormat(curr *gmproto.ConfigVersion, latest *gmproto.ConfigVersion) string {
|
||||||
|
|
|
@ -23,4 +23,4 @@ const AckMessagesURL = messagingBaseURL + "/AckMessages"
|
||||||
const registrationBaseURL = instantMessangingBaseURL + "/$rpc/google.internal.communications.instantmessaging.v1.Registration"
|
const registrationBaseURL = instantMessangingBaseURL + "/$rpc/google.internal.communications.instantmessaging.v1.Registration"
|
||||||
const RegisterRefreshURL = registrationBaseURL + "/RegisterRefresh"
|
const RegisterRefreshURL = registrationBaseURL + "/RegisterRefresh"
|
||||||
|
|
||||||
const ConfigUrl = "https://messages.google.com/web/config"
|
const ConfigURL = "https://messages.google.com/web/config"
|
||||||
|
|
Loading…
Reference in a new issue