Authenticate Handler API and SDK, and much more (#183)
This commit is contained in:
1 parent
acce195dcb
commit
28dbcd84bd
89 files changed
+5296
-1943
No files matched your search
+26
-11
@@ -32,25 +32,40 @@ func (r *Response) Decode(inStruct interface{}) (*Error, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// TODO Remove as we'll use the common err format for this
|
||||
if r.resp.StatusCode == 403 {
|
||||
// Nothing to be done
|
||||
return &Error{
|
||||
Status: http.StatusForbidden,
|
||||
Message: "Forbidden",
|
||||
}, nil
|
||||
}
|
||||
|
||||
if inStruct == nil {
|
||||
return nil, fmt.Errorf("nil value given to decode into and not a 204 response")
|
||||
}
|
||||
|
||||
r.Body = new(bytes.Buffer)
|
||||
if _, err := r.Body.ReadFrom(r.resp.Body); err != nil {
|
||||
return nil, fmt.Errorf("error reading response body: %w", err)
|
||||
apiErr := &Error{
|
||||
Status: int32(r.resp.StatusCode),
|
||||
}
|
||||
if r.resp.Body != nil {
|
||||
r.Body = new(bytes.Buffer)
|
||||
if _, err := r.Body.ReadFrom(r.resp.Body); err != nil {
|
||||
return nil, fmt.Errorf("error reading response body: %w", err)
|
||||
}
|
||||
|
||||
dec := json.NewDecoder(bytes.NewReader(r.Body.Bytes()))
|
||||
var apiErr Error
|
||||
if r.resp.StatusCode >= 400 {
|
||||
inStruct = &apiErr
|
||||
}
|
||||
if err := dec.Decode(inStruct); err != nil {
|
||||
return nil, fmt.Errorf("error decoding response: %w; response was %s", err, r.Body.String())
|
||||
if r.Body.Len() != 0 {
|
||||
dec := json.NewDecoder(bytes.NewReader(r.Body.Bytes()))
|
||||
if r.resp.StatusCode >= 400 {
|
||||
inStruct = apiErr
|
||||
}
|
||||
if err := dec.Decode(inStruct); err != nil {
|
||||
return nil, fmt.Errorf("error decoding response: %w; response was %s", err, r.Body.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
if r.resp.StatusCode >= 400 {
|
||||
return &apiErr, nil
|
||||
return apiErr, nil
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
|
||||
Reference in new issue
Block a user