-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #186 from simphony/175-error-payload
Error payload
- Loading branch information
Showing
16 changed files
with
562 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
remoteappmanager.rest.http package | ||
================================== | ||
|
||
Submodules | ||
---------- | ||
|
||
remoteappmanager.rest.http.httpstatus module | ||
-------------------------------------------- | ||
|
||
.. automodule:: remoteappmanager.rest.http.httpstatus | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
remoteappmanager.rest.http.payloaded_http_error module | ||
------------------------------------------------------ | ||
|
||
.. automodule:: remoteappmanager.rest.http.payloaded_http_error | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
|
||
Module contents | ||
--------------- | ||
|
||
.. automodule:: remoteappmanager.rest.http | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from tornado.web import HTTPError | ||
|
||
|
||
class PayloadedHTTPError(HTTPError): | ||
def __init__(self, status_code, | ||
payload=None, | ||
content_type=None, | ||
log_message=None, | ||
*args, **kwargs): | ||
"""Provides a HTTPError that contains a string payload to output | ||
as a response. If the payload is None, behaves like a regular | ||
HTTPError, producing no payload in the response. | ||
Parameters | ||
---------- | ||
payload: str or None | ||
The payload as a string | ||
content_type: str or None | ||
The content type of the payload | ||
log_message: str or None | ||
The log message. Passed to the HTTPError. | ||
""" | ||
super().__init__(status_code, log_message, *args, **kwargs) | ||
|
||
if payload is not None: | ||
if not isinstance(payload, str): | ||
raise ValueError("payload must be a string.") | ||
|
||
if content_type is None: | ||
content_type = "text/plain" | ||
else: | ||
if content_type is not None: | ||
raise ValueError("Content type specified, but no payload") | ||
|
||
self.content_type = content_type | ||
self.payload = payload |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.