Permalink
Browse files

Merge branch 'improve_exceptions' of git://github.com/richid/facepy

Conflicts:
	facepy/exceptions.py
	tests/test_exceptions.py
  • Loading branch information...
2 parents 7077bae + 839fa59 commit 2befa4547c16eff81ae5a15ddfdc3794fa7cd7eb @jgorset committed Aug 27, 2012
Showing with 21 additions and 3 deletions.
  1. +5 −2 facepy/exceptions.py
  2. +16 −1 tests/test_exceptions.py
@@ -1,7 +1,5 @@
class FacepyError(Exception):
"""Base class for exceptions raised by Facepy."""
- def __init__(self, message):
- self.message = message
class FacebookError(FacepyError):
@@ -10,6 +8,11 @@ def __init__(self, message=None, code=None):
self.message = message
self.code = code
+ if self.code:
+ message = '[%s] %s' % (self.code, self.message)
+
+ super(FacebookError, self).__init__(message)
+
class OAuthError(FacebookError):
"""Exception for Facebook errors specifically related to OAuth."""
@@ -5,13 +5,28 @@
from nose.tools import *
from facepy import *
+from facepy.exceptions import FacebookError
def test_facepy_error():
try:
raise FacepyError('<message>')
except FacepyError as exception:
- assert exception.message == '<message>'
+ assert_equal(exception.message, '<message>')
+ assert_equal(exception.__str__(), '<message>')
+ assert_equal(exception.__repr__(), 'FacepyError(\'<message>\',)')
+ assert_equal(exception.__unicode__(), u'<message>')
+
+
+def test_facebook_error():
+ try:
+ raise FacebookError('<message>', 100)
+ except FacebookError as exception:
+ assert_equal(exception.message, '<message>')
+ assert_equal(exception.code, 100)
+ assert_equal(exception.__str__(), '[100] <message>')
+ assert_equal(exception.__repr__(), 'FacebookError(\'[100] <message>\',)')
+ assert_equal(exception.__unicode__(), u'[100] <message>')
def test_facebookerror_can_be_pickled():

0 comments on commit 2befa45

Please sign in to comment.