From fb1efcdc36c7b9f4f89a2fd8f4e09014eae1f2de Mon Sep 17 00:00:00 2001 From: Ray Di Ciaccio Date: Thu, 26 Feb 2015 17:05:36 -0500 Subject: [PATCH] Add an error_callback to async calls to handle HTTP errors. --- firebase/firebase.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/firebase/firebase.py b/firebase/firebase.py index 2e55865..8daec5f 100644 --- a/firebase/firebase.py +++ b/firebase/firebase.py @@ -12,6 +12,8 @@ from .async import process_pool from .jsonutil import JSONEncoder +import requests + __all__ = ['FirebaseAuthentication', 'FirebaseApplication'] @@ -273,7 +275,7 @@ def get(self, url, name, params=None, headers=None, connection=None): self._authenticate(params, headers) return make_get_request(endpoint, params, headers, connection=connection) - def get_async(self, url, name, callback=None, params=None, headers=None): + def get_async(self, url, name, callback=None, error_callback=None, params=None, headers=None): """ Asynchronous GET request with the process pool. """ @@ -283,7 +285,7 @@ def get_async(self, url, name, callback=None, params=None, headers=None): endpoint = self._build_endpoint_url(url, name) self._authenticate(params, headers) process_pool.apply_async(make_get_request, - args=(endpoint, params, headers), callback=callback) + args=(endpoint, params, headers), callback=callback, error_callback=error_callback) @http_connection(60) def put(self, url, name, data, params=None, headers=None, connection=None): @@ -301,7 +303,7 @@ def put(self, url, name, data, params=None, headers=None, connection=None): return make_put_request(endpoint, data, params, headers, connection=connection) - def put_async(self, url, name, data, callback=None, params=None, headers=None): + def put_async(self, url, name, data, callback=None, error_callback=None, params=None, headers=None): """ Asynchronous PUT request with the process pool. """ @@ -313,7 +315,7 @@ def put_async(self, url, name, data, callback=None, params=None, headers=None): data = json.dumps(data, cls=JSONEncoder) process_pool.apply_async(make_put_request, args=(endpoint, data, params, headers), - callback=callback) + callback=callback, error_callback=error_callback) @http_connection(60) def post(self, url, data, params=None, headers=None, connection=None): @@ -328,7 +330,7 @@ def post(self, url, data, params=None, headers=None, connection=None): return make_post_request(endpoint, data, params, headers, connection=connection) - def post_async(self, url, data, callback=None, params=None, headers=None): + def post_async(self, url, data, callback=None, error_callback=None, params=None, headers=None): """ Asynchronous POST request with the process pool. """ @@ -339,7 +341,7 @@ def post_async(self, url, data, callback=None, params=None, headers=None): data = json.dumps(data, cls=JSONEncoder) process_pool.apply_async(make_post_request, args=(endpoint, data, params, headers), - callback=callback) + callback=callback, error_callback=error_callback) @http_connection(60) def patch(self, url, data, params=None, headers=None, connection=None): @@ -354,7 +356,7 @@ def patch(self, url, data, params=None, headers=None, connection=None): return make_patch_request(endpoint, data, params, headers, connection=connection) - def patch_async(self, url, data, callback=None, params=None, headers=None): + def patch_async(self, url, data, callback=None, error_callback=None, params=None, headers=None): """ Asynchronous PATCH request with the process pool. """ @@ -365,7 +367,7 @@ def patch_async(self, url, data, callback=None, params=None, headers=None): data = json.dumps(data, cls=JSONEncoder) process_pool.apply_async(make_patch_request, args=(endpoint, data, params, headers), - callback=callback) + callback=callback, error_callback=error_callback) @http_connection(60) def delete(self, url, name, params=None, headers=None, connection=None): @@ -379,7 +381,7 @@ def delete(self, url, name, params=None, headers=None, connection=None): self._authenticate(params, headers) return make_delete_request(endpoint, params, headers, connection=connection) - def delete_async(self, url, name, callback=None, params=None, headers=None): + def delete_async(self, url, name, callback=None, error_callback=None, params=None, headers=None): """ Asynchronous DELETE request with the process pool. """ @@ -389,4 +391,4 @@ def delete_async(self, url, name, callback=None, params=None, headers=None): endpoint = self._build_endpoint_url(url, name) self._authenticate(params, headers) process_pool.apply_async(make_delete_request, - args=(endpoint, params, headers), callback=callback) + args=(endpoint, params, headers), callback=callback, error_callback=error_callback)