~thisfred/desktopcouch/lp-673641

« back to all changes in this revision

Viewing changes to desktopcouch/records/http.py

Ah HTTP error (say, from proxy server) may not return JSON document so we can't depend on being able to decode one.  Catch and log those errors.

python-couchdb prepends its own "/" in requests, so our use of them can cause errors when talking to remote hosts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
234
234
        # Handle errors
235
235
        if status >= 400:
236
236
            if data is not None:
237
 
                data = couchdbjson.decode(data)
238
 
                # pylint: disable=E1103
239
 
                error = data.get('error'), data.get('reason')
240
 
                # pylint: enable=E1103
 
237
                try:
 
238
                    data = couchdbjson.decode(data)
 
239
                    # pylint: disable=E1103
 
240
                    error = data.get('error'), data.get('reason')
 
241
                    # pylint: enable=E1103
 
242
                except ValueError:
 
243
                    error = data
241
244
            elif method != 'HEAD':
242
245
                error = resp.read()
243
246
                self._return_connection(url, conn)
244
247
            else:
245
248
                error = ''
 
249
 
246
250
            if status == 401:
247
251
                raise Unauthorized(error)
248
252
            elif status == 404: