~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/http/_pycurl.py

Fix pycurl error reporting

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
# TODO: test reporting of http errors
20
20
 
 
21
import os
21
22
from StringIO import StringIO
22
23
 
23
24
import bzrlib
68
69
            return False
69
70
        elif code in (200, 302): # "ok", "found"
70
71
            return True
 
72
        elif code == 0:
 
73
            self._raise_curl_connection_error(curl)
71
74
        else:
72
 
            raise TransportError('http error %d probing for %s' %
73
 
                    (code, curl.getinfo(pycurl.EFFECTIVE_URL)))
 
75
            self._raise_curl_http_error(curl)
74
76
        
75
77
    def _get(self, relpath, ranges):
76
78
        curl = pycurl.Curl()
95
97
        elif code == 206 and (ranges is not None):
96
98
            sio.seek(0)
97
99
            return code, sio
 
100
        elif code == 0:
 
101
            self._raise_curl_connection_error(curl)
98
102
        else:
99
 
            raise TransportError('http error %d acccessing %s' % 
100
 
                    (code, curl.getinfo(pycurl.EFFECTIVE_URL)))
 
103
            self._raise_curl_http_error(curl)
 
104
 
 
105
    def _raise_curl_connection_error(self, curl):
 
106
        curl_errno = curl.getinfo(pycurl.OS_ERRNO)
 
107
        url = curl.getinfo(pycurl.EFFECTIVE_URL)
 
108
        raise ConnectionError('curl connection error (%s) on %s'
 
109
                              % (os.strerror(curl_errno), url))
 
110
 
 
111
    def _raise_curl_http_error(self, curl):
 
112
        code = curl.getinfo(pycurl.HTTP_CODE)
 
113
        url = curl.getinfo(pycurl.EFFECTIVE_URL)
 
114
        raise TransportError('http error %d probing for %s' %
 
115
                             (code, url))
101
116
 
102
117
    def _set_curl_options(self, curl):
103
118
        """Set options for all requests"""