Skip to content

Commit 6560840

Browse files
committed
chore(oauth2): add oauth2 error parse
1 parent 2b7986f commit 6560840

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

errors.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,15 @@ func checkForErrors(res *http.Response) error {
140140
return unknownServerError(res.StatusCode, string(out))
141141
}
142142

143+
if oauthErr, ok := bodyMap["error"].(string); ok {
144+
if oauthErr == "invalid_grant" {
145+
return ErrLogin
146+
}
147+
if desc, ok := bodyMap["error_description"].(string); ok && desc != "" {
148+
return unknownServerError(res.StatusCode, desc)
149+
}
150+
}
151+
143152
if scanResponse(bodyMap, "username", []string{fieldReqMsg, invalidUserMsg}, true) {
144153
return ErrInvalidUsername
145154
}

errors_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ func TestErrors(t *testing.T) {
9696
},
9797
expected: ErrLogin,
9898
},
99+
{
100+
res: &http.Response{
101+
StatusCode: 400,
102+
Body: readCloser(`{"error": "invalid_grant", "error_description": "Invalid credentials given."}`),
103+
},
104+
expected: ErrLogin,
105+
},
99106
{
100107
res: &http.Response{
101108
StatusCode: 400,

0 commit comments

Comments
 (0)