Make error messages more generic
Casey Deccio
8 years ago
520 | 520 | |
521 | 521 | # if there is no content, raise an exception |
522 | 522 | if self.res is None: |
523 | raise RemoteQueryTransportError('No content in HTTP response') | |
523 | raise RemoteQueryTransportError('No content in response') | |
524 | 524 | |
525 | 525 | # load the json content |
526 | 526 | try: |
527 | 527 | content = json.loads(self.res) |
528 | 528 | except ValueError: |
529 | raise RemoteQueryTransportError('JSON decoding of HTTP response failed: %s' % self.res) | |
529 | raise RemoteQueryTransportError('JSON decoding of response failed: %s' % self.res) | |
530 | 530 | |
531 | 531 | if 'version' not in content: |
532 | raise RemoteQueryTransportError('No version information in HTTP response.') | |
532 | raise RemoteQueryTransportError('No version information in response.') | |
533 | 533 | try: |
534 | 534 | major_vers, minor_vers = map(int, str(content['version']).split('.', 1)) |
535 | 535 | except ValueError: |
536 | raise RemoteQueryTransportError('Version of JSON input in HTTP response is invalid: %s' % content['version']) | |
536 | raise RemoteQueryTransportError('Version of JSON input in response is invalid: %s' % content['version']) | |
537 | 537 | |
538 | 538 | # ensure major version is a match and minor version is no greater |
539 | 539 | # than the current minor version |
540 | 540 | curr_major_vers, curr_minor_vers = map(int, str(DNS_TRANSPORT_VERSION).split('.', 1)) |
541 | 541 | if major_vers != curr_major_vers or minor_vers > curr_minor_vers: |
542 | raise RemoteQueryTransportError('Version %d.%d of JSON input in HTTP response is incompatible with this software.' % (major_vers, minor_vers)) | |
542 | raise RemoteQueryTransportError('Version %d.%d of JSON input in response is incompatible with this software.' % (major_vers, minor_vers)) | |
543 | 543 | |
544 | 544 | if 'responses' not in content: |
545 | raise RemoteQueryTransportError('No response information in HTTP response.') | |
545 | raise RemoteQueryTransportError('No DNS response information in response.') | |
546 | 546 | |
547 | 547 | for i in range(len(self.qtms)): |
548 | 548 | try: |
549 | 549 | self.qtms[i].deserialize_response(content['responses'][i]) |
550 | 550 | except IndexError: |
551 | raise RemoteQueryTransportError('Response information missing from HTTP response') | |
551 | raise RemoteQueryTransportError('DNS response information missing from response') | |
552 | 552 | except TransportMetaDeserializationError, e: |
553 | 553 | raise RemoteQueryTransportError(str(e)) |
554 | 554 |