Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an error_callback to async calls to handle HTTP errors. #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions firebase/firebase.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from .async import process_pool
from .jsonutil import JSONEncoder

import requests

__all__ = ['FirebaseAuthentication', 'FirebaseApplication']


Expand Down Expand Up @@ -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.
"""
Expand All @@ -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):
Expand All @@ -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.
"""
Expand All @@ -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):
Expand All @@ -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.
"""
Expand All @@ -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):
Expand All @@ -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.
"""
Expand All @@ -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):
Expand All @@ -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.
"""
Expand All @@ -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)