<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -332,7 +332,8 @@ class EpiOAuthResponse
   }
 }
 
-class EpiOAuthException extends Exception
+class EpiException extends Exception{}
+class EpiOAuthException extends EpiException
 {
   public static function raise($message, $code)
   {
@@ -347,7 +348,5 @@ class EpiOAuthException extends Exception
     }
   }
 }
-
-
 class EpiOAuthBadRequestException extends EpiOAuthException{}
 class EpiOAuthUnauthorizedException extends EpiOAuthException{}</diff>
      <filename>EpiOAuth.php</filename>
    </modified>
    <modified>
      <diff>@@ -131,19 +131,11 @@ class EpiTwitterJson implements ArrayAccess, Countable, IteratorAggregate
 
   public function __get($name)
   {
-    if(($this-&gt;__resp-&gt;code &lt; 200 || $this-&gt;__resp-&gt;code &gt;= 400) &amp;&amp; $name !== 'responseText' &amp;&amp; $name !== 'headers') // TODO: clean up
-    {
-      switch($this-&gt;__auth)
-      {
-        case EpiTwitter::EPITWITTER_AUTH_OAUTH:
-          EpiOAuthException::raise($this-&gt;__resp-&gt;data, $this-&gt;__resp-&gt;code);
-        case EpiTwitter::EPITWITTER_AUTH_BASIC:
-          throw new EpiTwitterException($this-&gt;__resp-&gt;data, $this-&gt;__resp-&gt;code);
-        default:
-          throw new Exception(&quot;Unknown EpiTwitter Exception.  Response: {$this-&gt;__resp-&gt;data}&quot;, $this-&gt;__resp-&gt;code);
-      }
-    }
+    $accessible = array('responseText'=&gt;1,'headers'=&gt;1);
+    if(($this-&gt;__resp-&gt;code &lt; 200 || $this-&gt;__resp-&gt;code &gt;= 400) &amp;&amp; !isset($accessible[$name]))
+      EpiTwitterException::raise($this-&gt;__resp);
 
+    // if no exception is thrown, continue
     $this-&gt;responseText = $this-&gt;__resp-&gt;data;
     $this-&gt;code         = $this-&gt;__resp-&gt;code;
     $this-&gt;headers      = $this-&gt;__resp-&gt;headers;
@@ -168,4 +160,29 @@ class EpiTwitterJson implements ArrayAccess, Countable, IteratorAggregate
   }
 }
 
-class EpiTwitterException extends Exception {}
+class EpiTwitterException extends EpiException 
+{
+  public static function raise($response)
+  {
+    $message = &quot;An exception occurred in EpiTwitter\n&quot;
+             . &quot;The response is {$response-&gt;data}\n&quot;
+             . &quot;The headers are &quot; . print_r($response-&gt;headers, true) . &quot;\n&quot;;
+    switch($response-&gt;code)
+    {
+      case 400:
+        throw new EpiTwitterBadRequestException($message, $response-&gt;code);
+      case 401:
+        throw new EpiTwitterNotAuthorizedException($message, $response-&gt;code);
+      case 403:
+        throw new EpiTwitterForbiddenException($message, $response-&gt;code);
+      case 404:
+        throw new EpiTwitterNotFoundException($message, $response-&gt;code);
+      default:
+        throw new EpiTwitterException($message, $response-&gt;code);
+    }
+  }
+}
+class EpiTwitterBadRequestException extends EpiTwitterException{}
+class EpiTwitterNotAuthorizedException extends EpiTwitterException{}
+class EpiTwitterForbiddenException extends EpiTwitterException{}
+class EpiTwitterNotFoundException extends EpiTwitterException{}</diff>
      <filename>EpiTwitter.php</filename>
    </modified>
    <modified>
      <diff>@@ -16,6 +16,7 @@ class EpiTwitterTest extends PHPUnit_Framework_TestCase
     $this-&gt;twitterObj = new EpiTwitter($consumer_key, $consumer_secret, $token, $secret);
     $this-&gt;twitterObjUnAuth = new EpiTwitter($consumer_key, $consumer_secret);
     $this-&gt;twitterObjBasic = new EpiTwitter();
+    $this-&gt;twitterObjBadAuth = new EpiTwitter('foo', 'bar', 'foo', 'bar');
     $this-&gt;id = '25451974';
     $this-&gt;screenName = 'jmathai_test';
     $this-&gt;twitterUsername = 'jmathai_test';
@@ -121,16 +122,6 @@ class EpiTwitterTest extends PHPUnit_Framework_TestCase
     $this-&gt;assertEquals($token-&gt;oauth_token, substr($authenticateUrl, (strpos($authenticateUrl, '=')+1)), &quot;token does not equal the one which was passed in&quot;);
   }
 
-  /**
-  * @expectedException EpiOAuthException
-  */
-  function testNoRequiredParameter()
-  {
-    $resp = $this-&gt;twitterObj-&gt;post_direct_messagesNew( array ( 'user' =&gt; $this-&gt;screenName, 'text' =&gt; ''));
-    $this-&gt;assertTrue(!empty($resp-&gt;response['error']), &quot;An empty direct message should return an error message&quot;);
-
-  }
-
   function testResponseAccess()
   {
     $resp = $this-&gt;twitterObj-&gt;get_statusesFollowers();
@@ -301,4 +292,31 @@ class EpiTwitterTest extends PHPUnit_Framework_TestCase
     $resp = $this-&gt;twitterObj-&gt;get_statusesFollowers();
     $this-&gt;assertTrue(!empty($resp-&gt;headers['Status']), 'header status response should not be empty');
   }
+
+  /**
+  * @expectedException EpiTwitterForbiddenException
+  */
+  function testNoRequiredParameter()
+  {
+    $resp = $this-&gt;twitterObj-&gt;post_direct_messagesNew( array ( 'user' =&gt; $this-&gt;screenName, 'text' =&gt; ''));
+    $this-&gt;assertTrue(!empty($resp-&gt;response['error']), &quot;An empty direct message should return an error message&quot;);
+  }
+
+  /**
+  * @expectedException EpiTwitterNotAuthorizedException
+  */
+  function testBadCredentials()
+  {
+    $resp = $this-&gt;twitterObjBadAuth-&gt;post_direct_messagesNew( array ( 'user' =&gt; $this-&gt;screenName, 'text' =&gt; 'hello world'));
+    $this-&gt;assertTrue(!empty($resp-&gt;response['error']), &quot;Bad credentials should return a not authorized exception&quot;);
+  }
+
+  /**
+  * @expectedException EpiTwitterNotFoundException
+  */
+  function testNonExistantUser()
+  {
+    $resp = $this-&gt;twitterObj-&gt;post_direct_messagesNew( array ( 'user' =&gt; 'jaisen_does_not_exist_and_dont_create_or_this_will_break', 'text' =&gt; 'seriously'));
+    $this-&gt;assertTrue(!empty($resp-&gt;response['error']), &quot;Sending a message to a user that doesn't exist should return a 404&quot;);
+  }
 }</diff>
      <filename>tests/EpiTwitterTest.php</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>889fee8f89fe1d19013cc8a08a8dbae724c14b41</id>
    </parent>
  </parents>
  <author>
    <name>Jaisen Mathai</name>
    <email>jaisen@jmathai.com</email>
  </author>
  <url>http://github.com/jmathai/twitter-async/commit/42934e1d8e7144906b18947309f9e25e84d53461</url>
  <id>42934e1d8e7144906b18947309f9e25e84d53461</id>
  <committed-date>2009-10-05T18:21:09-07:00</committed-date>
  <authored-date>2009-10-05T18:21:09-07:00</authored-date>
  <message>Initial checkin of exception refactoring. gh-18</message>
  <tree>f03353d19ef21435bc9b033b2e42b3823c893b8b</tree>
  <committer>
    <name>Jaisen Mathai</name>
    <email>jaisen@jmathai.com</email>
  </committer>
</commit>
