summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorZach Copley <zach@controlyourself.ca>2009-09-02 00:50:41 +0000
committerZach Copley <zach@controlyourself.ca>2009-09-02 00:50:41 +0000
commitf86fed357c07f1c1d2c633e8c2c730f205187e1a (patch)
treea3e858cd7b30cc78c03be1117dd47650236ccbd5 /lib
parent8b040eba4062bcb464f49e3e04d7a172a1d55c1e (diff)
Better error handling
Diffstat (limited to 'lib')
-rw-r--r--lib/twitter.php100
1 files changed, 42 insertions, 58 deletions
diff --git a/lib/twitter.php b/lib/twitter.php
index 455f7e7ef..676c9b20a 100644
--- a/lib/twitter.php
+++ b/lib/twitter.php
@@ -175,34 +175,7 @@ function broadcast_oauth($notice, $flink) {
try {
$status = $client->statusesUpdate($statustxt);
} catch (OAuthClientCurlException $e) {
-
- if ($e->getMessage() == 'The requested URL returned error: 401') {
-
- $errmsg = sprintf('User %1$s (user id: %2$s) has an invalid ' .
- 'Twitter OAuth access token.',
- $user->nickname, $user->id);
- common_log(LOG_WARNING, $errmsg);
-
- // Bad auth token! We need to delete the foreign_link
- // to Twitter and inform the user.
-
- remove_twitter_link($flink);
- return true;
-
- } else {
-
- // Some other error happened, so we should probably
- // try to send again later.
-
- $errmsg = sprintf('cURL error trying to send notice to Twitter ' .
- 'for user %1$s (user id: %2$s) - ' .
- 'code: %3$s message: %4$s.',
- $user->nickname, $user->id,
- $e->getCode(), $e->getMessage());
- common_log(LOG_WARNING, $errmsg);
-
- return false;
- }
+ return process_error($e, $flink);
}
if (empty($status)) {
@@ -210,9 +183,9 @@ function broadcast_oauth($notice, $flink) {
// This could represent a failure posting,
// or the Twitter API might just be behaving flakey.
- $errmsg = sprintf('No data returned by Twitter API when ' .
- 'trying to send update for %1$s (user id %2$s).',
- $user->nickname, $user->id);
+ $errmsg = sprintf('Twitter bridge - No data returned by Twitter API when ' .
+ 'trying to send update for %1$s (user id %2$s).',
+ $user->nickname, $user->id);
common_log(LOG_WARNING, $errmsg);
return false;
@@ -220,7 +193,7 @@ function broadcast_oauth($notice, $flink) {
// Notice crossed the great divide
- $msg = sprintf('Twitter bridge posted notice %s to Twitter using OAuth.',
+ $msg = sprintf('Twitter bridge - posted notice %s to Twitter using OAuth.',
$notice->id);
common_log(LOG_INFO, $msg);
@@ -239,46 +212,57 @@ function broadcast_basicauth($notice, $flink)
try {
$status = $client->statusesUpdate($statustxt);
} catch (BasicAuthCurlException $e) {
-
- if ($e->getMessage() == 'The requested URL returned error: 401') {
-
- $errmsg = sprintf('User %1$s (user id: %2$s) has an invalid ' .
- 'Twitter screen_name/password combo.',
- $user->nickname, $user->id);
- common_log(LOG_WARNING, $errmsg);
-
- remove_twitter_link($flink);
- return true;
-
- } else {
-
- $errmsg = sprintf('cURL error trying to send notice to Twitter ' .
- 'for user %1$s (user id: %2$s) - ' .
- 'code: %3$s message: %4$s.',
- $user->nickname, $user->id,
- $e->getCode(), $e->getMessage());
- common_log(LOG_WARNING, $errmsg);
-
- return false;
- }
+ return process_error($e, $flink);
}
if (empty($status)) {
- $errmsg = sprintf('No data returned by Twitter API when ' .
- 'trying to send update for %1$s (user id %2$s).',
- $user->nickname, $user->id);
+ $errmsg = sprintf('Twitter bridge - No data returned by Twitter API when ' .
+ 'trying to send update for %1$s (user id %2$s).',
+ $user->nickname, $user->id);
common_log(LOG_WARNING, $errmsg);
return false;
}
- $msg = sprintf('Twitter bridge posted notice %s to Twitter using basic auth.',
+ $msg = sprintf('Twitter bridge - posted notice %s to Twitter using basic auth.',
$notice->id);
common_log(LOG_INFO, $msg);
return true;
+}
+
+function process_error($e, $flink)
+{
+ $user = $flink->getUser();
+ $errmsg = $e->getMessage();
+ $delivered = false;
+
+ switch($errmsg) {
+ case 'The requested URL returned error: 401':
+ $logmsg = sprintf('Twiter bridge - User %1$s (user id: %2$s) has an invalid ' .
+ 'Twitter screen_name/password combo or an invalid acesss token.',
+ $user->nickname, $user->id);
+ $delivered = true;
+ remove_twitter_link($flink);
+ break;
+ case 'The requested URL returned error: 403':
+ $logmsg = sprintf('Twitter bridge - User %1$s (user id: %2$s) has exceeded ' .
+ 'his/her Twitter request limit.',
+ $user->nickname, $user->id);
+ break;
+ default:
+ $logmsg = sprintf('Twitter bridge - cURL error trying to send notice to Twitter ' .
+ 'for user %1$s (user id: %2$s) - ' .
+ 'code: %3$s message: %4$s.',
+ $user->nickname, $user->id,
+ $e->getCode(), $e->getMessage());
+ break;
+ }
+
+ common_log(LOG_WARNING, $logmsg);
+ return $delivered;
}
function format_status($notice)