From f51bdeaec7dcc05c4927b377ec113e1dbefc41c6 Mon Sep 17 00:00:00 2001 From: bytedream Date: Mon, 16 May 2022 20:03:52 +0200 Subject: [PATCH] Add error return in some login failure cases (#30) --- crunchyroll.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/crunchyroll.go b/crunchyroll.go index 60b4320..d3b1ce8 100644 --- a/crunchyroll.go +++ b/crunchyroll.go @@ -97,6 +97,13 @@ func LoginWithCredentials(user string, password string, locale LOCALE, client *h if loginResp.StatusCode != http.StatusOK { return nil, fmt.Errorf("failed to auth with credentials: %s", loginResp.Status) + } else { + var loginRespBody map[string]interface{} + json.NewDecoder(loginResp.Body).Decode(&loginRespBody) + + if loginRespBody["error"].(bool) { + return nil, fmt.Errorf("an unexpected login error occoured: %s", loginRespBody["message"]) + } } return LoginWithSessionID(sessionID, locale, client)