-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f1f5d9
commit e2e4877
Showing
1 changed file
with
61 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
""" | ||
Handles formatting of http responses | ||
""" | ||
|
||
# Default errors | ||
ERRORS = { | ||
'NotFound': { | ||
'message': 'Chapter 404: The Lost Resource. A careful and diligent ' + | ||
'search has been made for the desired resource, ' + | ||
'but it just cannot be found.', | ||
'status': 404, | ||
'info': 'Visit the API Docs to see available endpoints' | ||
}, | ||
'InternalServerError': { | ||
'message': 'Sorry about this. It\'s not you, it\'s us. ' + | ||
'We just couldn\'t handle your request', | ||
'status': 500, | ||
'info': 'Please try again. If this persists, let us know' | ||
} | ||
} | ||
|
||
|
||
class Response(): | ||
""" | ||
Has methods for populating response templates with dynamic data | ||
and returns it | ||
""" | ||
|
||
@staticmethod | ||
def success(**kwargs): | ||
""" | ||
Args: | ||
dynamic success data | ||
Returns: | ||
Populated success template | ||
""" | ||
success_response = { | ||
'status': 'success', | ||
'meta': {}, | ||
'message': '', | ||
} | ||
for item in kwargs: | ||
success_response[item] = kwargs[item] | ||
return success_response | ||
|
||
@staticmethod | ||
def failed(**kwargs): | ||
""" | ||
Args: | ||
dynamic errors | ||
Returns: | ||
Populated fail template | ||
""" | ||
fail_response = { | ||
'status': 'failed', | ||
'message': '', | ||
'meta': {} | ||
} | ||
for item in kwargs: | ||
fail_response[item] = kwargs[item] | ||
return fail_response |