Prevent err from being clobbered when JSON unmarshals to nil result.

This commit is contained in:
Richard Lewis 2018-03-27 10:06:39 +01:00
parent a7fc80c806
commit 00a2f789f0
1 changed files with 8 additions and 1 deletions

View File

@ -281,7 +281,14 @@ func (cli *Client) register(u string, req *ReqRegister) (resp *RespRegister, uia
}
if httpErr.Code == 401 {
// body should be RespUserInteractive, if it isn't, fail with the error
err = json.Unmarshal(bodyBytes, &uiaResp)
err2 := json.Unmarshal(bodyBytes, &uiaResp)
if err2 != nil {
err = err2
return
}
if len(uiaResp.Flows) > 0 {
err = nil // We successfully unmarshalled into uiaresp so any HTTP errors can be discarded
}
return
}
return