diff --git a/eve_proxy/models.py b/eve_proxy/models.py index 8fc4c66..cd743bf 100755 --- a/eve_proxy/models.py +++ b/eve_proxy/models.py @@ -48,7 +48,7 @@ class CachedDocumentManager(models.Manager): 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 the cache. @@ -119,10 +119,9 @@ class CachedDocumentManager(models.Manager): # Check for the presence errors. Only check the bare minimum, # generic stuff that applies to most or all queries. User-level code # should check for the more specific errors. - if dom: error_node = dom.getElementsByTagName('error') - if error_node: + if error_node and exceptions: error_code = error_node[0].getAttribute('code') # User specified an invalid userid and/or auth key. if error_code == '203': diff --git a/eve_proxy/views.py b/eve_proxy/views.py index 5748c81..7e4d227 100755 --- a/eve_proxy/views.py +++ b/eve_proxy/views.py @@ -23,14 +23,18 @@ def retrieve_xml(request): if url_path == '/' or url_path == '': # 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: return HttpResponse('No Service ID provided.') # The query system will retrieve a cached_doc that was either previously # 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. if cached_doc: