handle session queries not being valid

This commit is contained in:
Hekmon 2022-04-29 11:31:01 +02:00
parent 48595f25fa
commit 037df1d16f
No known key found for this signature in database
GPG key ID: 8C27AA76AB6EFF96

View file

@ -70,6 +70,10 @@ func LoginWithCredentials(user string, password string, locale LOCALE, client *h
} }
defer sessResp.Body.Close() defer sessResp.Body.Close()
if sessResp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("Failed to start session: %s", sessResp.Status)
}
var data map[string]interface{} var data map[string]interface{}
body, _ := io.ReadAll(sessResp.Body) body, _ := io.ReadAll(sessResp.Body)
json.Unmarshal(body, &data) json.Unmarshal(body, &data)
@ -109,6 +113,11 @@ func LoginWithSessionID(sessionID string, locale LOCALE, client *http.Client) (*
return nil, err return nil, err
} }
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("Failed to start session: %s", resp.Status)
}
json.NewDecoder(resp.Body).Decode(&jsonBody) json.NewDecoder(resp.Body).Decode(&jsonBody)
if _, ok := jsonBody["message"]; ok { if _, ok := jsonBody["message"]; ok {
return nil, errors.New("invalid session id") return nil, errors.New("invalid session id")