Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly handle error responses in python3 #214

Merged
merged 1 commit into from
Apr 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion swaggerpy/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import sys

import six
from yelp_bytes import from_bytes

from . import swagger_type
from .swagger_type import SwaggerTypeCheck
Expand All @@ -35,7 +36,7 @@ def handle_response_errors(e):
if hasattr(e, 'response'):
kwargs['response'] = e.response
if hasattr(e.response, 'text'):
args[0] += (' : ' + e.response.text)
args[0] += ' : ' + from_bytes(e.response.text)

if hasattr(e, 'request'):
kwargs['request'] = e.request
Expand Down
21 changes: 20 additions & 1 deletion tests/integration/async_http_client_test.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# -*- coding: utf-8 -*-

import socket
import threading
import time
import unittest

import bottle
import pytest

from swaggerpy.async_http_client import AsynchronousHttpClient
from swaggerpy.exception import HTTPError
from swaggerpy.response import HTTPFuture


ROUTE_1_RESPONSE = b"HEY BUDDY"
Expand Down Expand Up @@ -71,3 +73,20 @@ def test_multiple_requests_against_async_client(self):

self.assertEqual(resp_one.text, ROUTE_1_RESPONSE)
self.assertEqual(resp_two.text, ROUTE_2_RESPONSE)

def test_erroring_request(self):
port = get_hopefully_free_port()
launch_threaded_http_server(port)

client = AsynchronousHttpClient()

params = {
'method': b'GET',
'headers': {},
'url': 'http://localhost:{0}/404'.format(port),
'params': {},
}

future = HTTPFuture(client, params, lambda x: x)
with pytest.raises(HTTPError):
future.result(timeout=1)