@@ -92,11 +92,16 @@ func checkForErrors(res *http.Response) error {
9292 res .Body .Close ()
9393 }()
9494
95+ out , err := ioutil .ReadAll (res .Body )
96+ if err != nil {
97+ return unknownServerError (res .StatusCode , err .Error ())
98+ }
99+
95100 switch res .StatusCode {
96101 case 400 :
97102 bodyMap := make (map [string ]interface {})
98- if err := json .NewDecoder ( res . Body ). Decode ( & bodyMap ); err != nil {
99- return unknownError (res .StatusCode , err )
103+ if err := json .Unmarshal ( out , & bodyMap ); err != nil {
104+ return unknownServerError (res .StatusCode , fmt . Sprintf ( "error decoding json response (%s): %s" , err , string ( out )) )
100105 }
101106
102107 if scanResponse (bodyMap , "username" , []string {fieldReqMsg , invalidUserMsg }, true ) {
@@ -166,8 +171,7 @@ func checkForErrors(res *http.Response) error {
166171 return ErrTagNotFound
167172 }
168173 }
169-
170- return unknownError (res .StatusCode , bodyMap )
174+ return unknownServerError (res .StatusCode , string (out ))
171175 case 401 :
172176 return ErrUnauthorized
173177 case 403 :
@@ -183,11 +187,7 @@ func checkForErrors(res *http.Response) error {
183187 case 500 :
184188 return ErrServerError
185189 default :
186- out , err := ioutil .ReadAll (res .Body )
187- if err != nil {
188- return unknownError (res .StatusCode , err )
189- }
190- return unknownError (res .StatusCode , out )
190+ return unknownServerError (res .StatusCode , string (out ))
191191 }
192192}
193193
@@ -224,8 +224,8 @@ func arrayContains(search string, completeMatch bool, array []string) bool {
224224 return false
225225}
226226
227- func unknownError ( sc int , k interface {} ) error {
228- return fmt .Errorf (formatErrUnknown , sc , k )
227+ func unknownServerError ( statusCode int , message string ) error {
228+ return fmt .Errorf (formatErrUnknown , statusCode , message )
229229}
230230
231231func scanResponse (
0 commit comments