diff --git a/.bumpversion.cfg b/.bumpversion.cfg index e0782c10..0c098fb6 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 2.4.7 +current_version = 2.4.8 [bumpversion:file:.env] diff --git a/.env b/.env index 11308709..ecc7e458 100644 --- a/.env +++ b/.env @@ -11,7 +11,7 @@ fi export PROJECT_NAME=$OPEN_PROJECT_NAME export PROJECT_DIR="$PWD" -export PROJECT_VERSION="2.4.7" +export PROJECT_VERSION="2.4.8" if [ ! -d "venv" ]; then if ! hash pyvenv 2>/dev/null; then diff --git a/.travis.yml b/.travis.yml index adb5efdf..3650107d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,10 +19,13 @@ matrix: env: TOXENV=pypy3 - os: osx language: generic - env: TOXENV=py34 + env: TOXENV=py35 - os: osx language: generic - env: TOXENV=py35 + env: TOXENV=py36 + - os: osx + language: generic + env: TOXENV=py37 before_install: - "./scripts/before_install.sh" install: diff --git a/CHANGELOG.md b/CHANGELOG.md index 8715080a..f0b60300 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,10 @@ Ideally, within a virtual environment. Changelog ========= +### 2.4.8 - April 7, 2019 +- Fixed issue #762 - HTTP errors crash with selectable output types +- Fixed MacOS testing via travis - added testing accross all the same Python versions tested on Linux + ### 2.4.7 - March 28, 2019 - Fixed API documentation with selectable output types diff --git a/hug/_version.py b/hug/_version.py index ffba2818..922de651 100644 --- a/hug/_version.py +++ b/hug/_version.py @@ -21,4 +21,4 @@ """ from __future__ import absolute_import -current = "2.4.7" +current = "2.4.8" diff --git a/hug/api.py b/hug/api.py index 90f90321..22367954 100644 --- a/hug/api.py +++ b/hug/api.py @@ -369,7 +369,8 @@ def server(self, default_not_found=True, base_url=None): def error_serializer(request, response, error): response.content_type = self.output_format.content_type - response.body = self.output_format({"errors": {error.title: error.description}}) + response.body = self.output_format({"errors": {error.title: error.description}}, + request, response) falcon_api.set_error_serializer(error_serializer) return falcon_api diff --git a/scripts/before_install.sh b/scripts/before_install.sh index 85c818dd..51d88bb3 100755 --- a/scripts/before_install.sh +++ b/scripts/before_install.sh @@ -1,4 +1,4 @@ -#! /bin/bash + #! /bin/bash echo $TRAVIS_OS_NAME @@ -16,6 +16,10 @@ echo $TRAVIS_OS_NAME python_minor=4;; py35) python_minor=5;; + py36) + python_minor=6;; + py37) + python_minor=7;; esac latest_version=`pyenv install --list | grep -e "^[ ]*3\.$python_minor" | tail -1` diff --git a/setup.py b/setup.py index 48dc9cb2..59cd55c0 100755 --- a/setup.py +++ b/setup.py @@ -75,7 +75,7 @@ def list_modules(dirname): setup( name='hug', - version='2.4.7', + version='2.4.8', description='A Python framework that makes developing APIs ' 'as simple as possible, but no simpler.', long_description=long_description, diff --git a/tests/test_output_format.py b/tests/test_output_format.py index 870e8384..d9fe3455 100644 --- a/tests/test_output_format.py +++ b/tests/test_output_format.py @@ -268,6 +268,26 @@ class FakeRequest(object): assert formatter('hi', request, response) == b'"hi"' +def test_accept_with_http_errors(): + """Ensure that content type based output formats work for HTTP error responses""" + formatter = hug.output_format.accept({'application/json': hug.output_format.json, + 'text/plain': hug.output_format.text}, + default=hug.output_format.json) + + api = hug.API('test_accept_with_http_errors') + hug.default_output_format(api=api)(formatter) + + @hug.get('/500', api=api) + def error_500(): + raise hug.HTTPInternalServerError('500 Internal Server Error', + 'This is an example') + + response = hug.test.get(api, '/500') + assert response.status == '500 Internal Server Error' + assert response.data == { + 'errors': {'500 Internal Server Error': 'This is an example'}} + + def test_suffix(): """Ensure that it's possible to route the output type format by the suffix of the requested URL""" formatter = hug.output_format.suffix({'.js': hug.output_format.json, '.html': hug.output_format.text})