Skip to content

Commit

Permalink
Merge 5600d07 into fc6362d
Browse files Browse the repository at this point in the history
  • Loading branch information
timothycrosley committed Apr 7, 2019
2 parents fc6362d + 5600d07 commit b07c787
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ Ideally, within a virtual environment.
Changelog
=========

### 2.4.8 - TBD
- Fixed issue #762 - HTTP errors crash with selectable output types

### 2.4.7 - March 28, 2019
- Fixed API documentation with selectable output types

Expand Down
3 changes: 2 additions & 1 deletion hug/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion scripts/before_install.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /bin/bash
#! /bin/bash

echo $TRAVIS_OS_NAME

Expand All @@ -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`

Expand Down
20 changes: 20 additions & 0 deletions tests/test_output_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down

0 comments on commit b07c787

Please sign in to comment.