Skip to content
Browse files

better error handling

  • Loading branch information...
1 parent c23a177 commit b0dd97181f54839bc78a133d63c95b23fa98d092 @jlongster jlongster committed Feb 23, 2012
Showing with 8 additions and 21 deletions.
  1. +8 −10 basket/base.py
  2. +0 −11 basket/ham.py
View
18 basket/base.py
@@ -4,7 +4,7 @@
from django.conf import settings
BASKET_URL = settings.BASKET_URL
except (ImportError, AttributeError):
- BASKET_URL = 'https://basket.mozilla.com'
+ BASKET_URL = 'http://localhost:8000'
import requests
@@ -24,11 +24,6 @@ def basket_url(method, token=None):
def parse_response(res):
"""Parse the result of a basket API call, raise exception on error"""
- if res.error:
- raise BasketException('Error connecting to %s: %s. Ensure that '
- 'BASKET_URL is configured correctly in your '
- 'settings file.' % (res.url, res.error))
-
if res.status_code != 200:
raise BasketException('%s request returned from basket: %s' %
(res.status_code, res.content))
@@ -50,10 +45,13 @@ def request(method, action, data=None, token=None, params=None):
if '__iter__' in data['newsletters']:
data['newsletters'] = ','.join(data['newsletters'])
- res = requests.request(method,
- basket_url(action, token),
- data=data,
- params=params)
+ try:
+ res = requests.request(method,
+ basket_url(action, token),
+ data=data,
+ params=params)
+ except requests.exceptions.ConnectionError:
+ raise BasketException("Error connecting to basket")
return parse_response(res)
View
11 basket/ham.py
@@ -1,11 +0,0 @@
-
-import base
-errored = 0
-for i in range(600):
- print i
- code = base.subscribe('t@example.com', 'mozilla-and-you')
- if code == 500:
- error = error + 1
-print error
-
-

0 comments on commit b0dd971

Please sign in to comment.
Something went wrong with that request. Please try again.