def test_from_http_status_with_errors_and_response(): message = "message" errors = ["1", "2"] response = mock.sentinel.response exception = exceptions.from_http_status( http_client.NOT_FOUND, message, errors=errors, response=response ) assert isinstance(exception, exceptions.NotFound) assert exception.code == http_client.NOT_FOUND assert exception.message == message assert exception.errors == errors assert exception.response == response
def _error_result_to_exception(error_result): """Maps BigQuery error reasons to an exception. The reasons and their matching HTTP status codes are documented on the `troubleshooting errors`_ page. .. _troubleshooting errors: https://cloud.google.com/bigquery\ /troubleshooting-errors Args: error_result (Mapping[str, str]): The error result from BigQuery. Returns: google.cloud.exceptions.GoogleAPICallError: The mapped exception. """ reason = error_result.get("reason") status_code = _ERROR_REASON_TO_EXCEPTION.get( reason, http.client.INTERNAL_SERVER_ERROR) return exceptions.from_http_status(status_code, error_result.get("message", ""), errors=[error_result])
def test_from_http_status_unknown_code(): message = 'message' status_code = 156 exception = exceptions.from_http_status(status_code, message) assert exception.code == status_code assert exception.message == message
def test_from_http_status(): message = 'message' exception = exceptions.from_http_status(http_client.NOT_FOUND, message) assert exception.code == http_client.NOT_FOUND assert exception.message == message assert exception.errors == []
def test_from_http_status_unknown_code(): message = "message" status_code = 156 exception = exceptions.from_http_status(status_code, message) assert exception.code == status_code assert exception.message == message
def test_from_http_status(): message = "message" exception = exceptions.from_http_status(http_client.NOT_FOUND, message) assert exception.code == http_client.NOT_FOUND assert exception.message == message assert exception.errors == []