Skip to content

Commit

Permalink
Merge pull request #44 from hydralabs/handle-remoting-error
Browse files Browse the repository at this point in the history
Handle remoting error
  • Loading branch information
njoyce committed Jan 25, 2015
2 parents cfa5825 + 32b2e24 commit d85fb11
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
12 changes: 6 additions & 6 deletions pyamf/amf3.py
Expand Up @@ -12,11 +12,11 @@
L{ByteArray} and L{ArrayCollection}.
@see: U{Official AMF3 Specification in English
<http://opensource.adobe.com/wiki/download/attachments/1114283/amf3_spec_05_05_08.pdf>}
<http://opensource.adobe.com/wiki/download/attachments/1114283/amf3_spec_05_05_08.pdf>}
@see: U{Official AMF3 Specification in Japanese
<http://opensource.adobe.com/wiki/download/attachments/1114283/JP_amf3_spec_121207.pdf>}
<http://opensource.adobe.com/wiki/download/attachments/1114283/JP_amf3_spec_121207.pdf>}
@see: U{AMF3 documentation on OSFlash
<http://osflash.org/documentation/amf3>}
<http://osflash.org/documentation/amf3>}
@since: 0.1
"""
Expand Down Expand Up @@ -59,7 +59,7 @@
#: In AMF 3 integers are serialized using a variable length signed 29-bit
#: integer.
#: @see: U{Parsing Integers on OSFlash (external)
#: <http://osflash.org/documentation/amf3/parsing_integers>}
#: <http://osflash.org/amf3/parsing_integers>}
TYPE_INTEGER = '\x04'
#: This type is used to encode an ActionScript Number or an ActionScript
#: C{int} of value greater than or equal to 2^28 or an ActionScript uint of
Expand Down Expand Up @@ -849,8 +849,8 @@ def readInteger(self, signed=True):
@type signed: C{bool}
@see: U{Parsing integers on OSFlash
<http://osflash.org/documentation/amf3/parsing_integers>} for the AMF3
integer data format.
<http://osflash.org/amf3/parsing_integers>} for the AMF3 integer data
format.
"""
return decode_int(self.stream, signed)

Expand Down
22 changes: 18 additions & 4 deletions pyamf/remoting/amf3.py
Expand Up @@ -216,18 +216,32 @@ def __call__(self, amf_request, **kwargs):
ro_request = amf_request.body[0]

try:
return self._getBody(amf_request, ro_request, **kwargs)
body = self._getBody(amf_request, ro_request, **kwargs)
except (KeyboardInterrupt, SystemExit):
raise
except:
if self.logger:
fault = self.buildErrorResponse(ro_request)

if hasattr(self.gateway, 'onServiceError'):
self.gateway.onServiceError(ro_request, fault)
elif self.logger:
self.logger.exception(
'Unexpected error while processing request %r',
get_service_name(ro_request)
)

return remoting.Response(self.buildErrorResponse(ro_request),
status=remoting.STATUS_ERROR)
body = remoting.Response(fault, status=remoting.STATUS_ERROR)

ro_response = body.body

dsid = ro_request.headers.get('DSId', None)

if not dsid or dsid == 'nil':
dsid = generate_random_id()

ro_response.headers.setdefault('DSId', dsid)

return body


def get_service_name(ro_request):
Expand Down

0 comments on commit d85fb11

Please sign in to comment.