The fetch() method will throw an OAuthException if the returned http status code is in the 4xx or 5xx range:
<?php
// Querying Twitter with bad login details
try {
$oauth->fetch('https://api.twitter.com/1.1/favorites/list.json');
}
catch(Exception $e) {
echo $e->getCode(); // 401
// Message generated by OAuth class
echo $e->getMessage(); // Invalid auth/bad request (got a 401, expected HTTP/1.1 20X or a redirect)
// Message returned from Twitter
echo $e->lastResponse; // {"errors":[{"message":"Could not authenticate you","code":32}]}
}