Permalink
Browse files

fix bug in request HTTP XML (HRX)

  • Loading branch information...
1 parent 624ae3a commit 29f4cd7225e50fee621c220248269f4b41e87bc1 @nycholas nycholas committed Feb 11, 2013
Showing with 12 additions and 9 deletions.
  1. +6 −3 flask_jsonrpc/helpers.py
  2. +6 −6 flask_jsonrpc/site.py
View
9 flask_jsonrpc/helpers.py
@@ -3,7 +3,7 @@
# All rights reserved.
from functools import wraps
-from flask import current_app, request, jsonify
+from flask import current_app, request, jsonify, json
from flask_jsonrpc.exceptions import InvalidCredentialsError, InvalidParamsError
@@ -22,10 +22,13 @@ def extract_raw_data_request(request):
if request.method == 'GET':
return request.query_string
elif request.method == 'POST':
- if request.data:
+ # True if the request was triggered via a JavaScript
+ # XMLHttpRequest
+ if request.is_xhr:
+ return json.dumps(request.form.to_dict())
+ elif request.data:
return request.data
elif request.form.to_dict():
- #return '&'.join(['{}={}'.format(k,v) for k,v in request.form.to_dict().items()])
return request.form.to_dict().keys()[0]
return ''
View
12 flask_jsonrpc/site.py
@@ -140,7 +140,7 @@ def response_dict(self, request, D, is_batch=False, version_hint='1.0'):
'1.1': lambda f, r, p: f(*encode_arg11(p), **encode_kw(encode_kw11(p))),
'1.0': lambda f, r, p: f(*p)
}
-
+
try:
# params: An Array or Object, that holds the actual parameter values
# for the invocation of the procedure. Can be omitted if empty.
@@ -189,15 +189,15 @@ def response_dict(self, request, D, is_batch=False, version_hint='1.0'):
except Error, e:
#got_request_exception.connect(log_exception, current_app._get_current_object())
-
+
response['error'] = e.json_rpc_format
if version in ('1.1', '2.0') and 'result' in response:
response.pop('result')
status = e.status
except Exception, e:
# exception missed by others
#got_request_exception.connect(log_exception, current_app._get_current_object())
-
+
other_error = OtherError(e)
response['error'] = other_error.json_rpc_format
status = other_error.status
@@ -218,7 +218,7 @@ def dispatch(self, request, method=''):
# json-rpc response
response = self.empty_response()
raw_data = extract_raw_data_request(request)
-
+
try:
if request.method == 'GET':
valid, D = self.validate_get(request, method)
@@ -230,8 +230,8 @@ def dispatch(self, request, method=''):
else:
try:
D = json.loads(raw_data)
- except:
- raise InvalidRequestError
+ except Exception, e:
+ raise InvalidRequestError(e.message)
if type(D) is list:
response = [self.response_dict(request, d, is_batch=True)[0] for d in D]

0 comments on commit 29f4cd7

Please sign in to comment.