response: add json responses (500, 400 and 200)
This commit is contained in:
parent
9bc2c9eb4b
commit
b48d55a420
|
@ -1,4 +1,5 @@
|
|||
|
||||
import json
|
||||
import pprint
|
||||
import sys
|
||||
import traceback
|
||||
|
@ -119,3 +120,20 @@ def template_response(templatename, values):
|
|||
msg = serve_template(templatename, **values)
|
||||
return HTTPResponse(200, 'OK', headers, msg)
|
||||
|
||||
def json_response(msg):
|
||||
headers = HTTPHeader({'Content-Type': ['application/json'], 'Cache-Control': ['no-cache']})
|
||||
msg = json.dumps(msg)
|
||||
return HTTPResponse(200, 'OK', headers, msg)
|
||||
|
||||
def json_bad_request(msg):
|
||||
headers = HTTPHeader({'Content-Type': ['application/json'],
|
||||
'Cache-Control': ['no-cache']})
|
||||
msg = json.dumps(msg)
|
||||
return HTTPResponse(400, 'Bad Request', headers, msg)
|
||||
|
||||
def json_error(msg):
|
||||
headers = HTTPHeader({'Content-Type': ['application/json'],
|
||||
'Cache-Control': ['no-cache']})
|
||||
msg = json.dumps(msg)
|
||||
return HTTPResponse(500, 'Internal Server Error', headers, msg)
|
||||
|
||||
|
|
Reference in New Issue