mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 23:02:19 +00:00
Added further error checking, and the ability for view to provide raw errors instead of exceptions
This commit is contained in:
@@ -48,7 +48,7 @@ class CachedDocumentManager(models.Manager):
|
|||||||
|
|
||||||
return dom
|
return dom
|
||||||
|
|
||||||
def api_query(self, url_path, params=None, no_cache=False):
|
def api_query(self, url_path, params=None, no_cache=False, exceptions=True):
|
||||||
"""
|
"""
|
||||||
Transparently handles querying EVE API or retrieving the document from
|
Transparently handles querying EVE API or retrieving the document from
|
||||||
the cache.
|
the cache.
|
||||||
@@ -119,10 +119,9 @@ class CachedDocumentManager(models.Manager):
|
|||||||
# Check for the presence errors. Only check the bare minimum,
|
# Check for the presence errors. Only check the bare minimum,
|
||||||
# generic stuff that applies to most or all queries. User-level code
|
# generic stuff that applies to most or all queries. User-level code
|
||||||
# should check for the more specific errors.
|
# should check for the more specific errors.
|
||||||
|
|
||||||
if dom:
|
if dom:
|
||||||
error_node = dom.getElementsByTagName('error')
|
error_node = dom.getElementsByTagName('error')
|
||||||
if error_node:
|
if error_node and exceptions:
|
||||||
error_code = error_node[0].getAttribute('code')
|
error_code = error_node[0].getAttribute('code')
|
||||||
# User specified an invalid userid and/or auth key.
|
# User specified an invalid userid and/or auth key.
|
||||||
if error_code == '203':
|
if error_code == '203':
|
||||||
|
|||||||
@@ -23,14 +23,18 @@ def retrieve_xml(request):
|
|||||||
|
|
||||||
if url_path == '/' or url_path == '':
|
if url_path == '/' or url_path == '':
|
||||||
# If they don't provide any kind of query, shoot a quick error message.
|
# If they don't provide any kind of query, shoot a quick error message.
|
||||||
return HttpResponse('No API query specified.')
|
return HttpResponseNotFound('No API query specified.')
|
||||||
|
|
||||||
if 'userID' in params and not 'service' in params:
|
if 'userID' in params and not 'service' in params:
|
||||||
return HttpResponse('No Service ID provided.')
|
return HttpResponse('No Service ID provided.')
|
||||||
|
|
||||||
# The query system will retrieve a cached_doc that was either previously
|
# The query system will retrieve a cached_doc that was either previously
|
||||||
# or newly cached depending on cache intervals.
|
# or newly cached depending on cache intervals.
|
||||||
cached_doc = CachedDocument.objects.api_query(url_path, params)
|
try:
|
||||||
|
cached_doc = CachedDocument.objects.api_query(url_path, params, exceptions=False)
|
||||||
|
except:
|
||||||
|
return HttpResponseServerError()
|
||||||
|
|
||||||
# Return the document's body as XML.
|
# Return the document's body as XML.
|
||||||
|
|
||||||
if cached_doc:
|
if cached_doc:
|
||||||
|
|||||||
Reference in New Issue
Block a user