[twitter] Add HTTP error code handling
This commit is contained in:
parent
9d2c8902d3
commit
b07e4bd59c
|
@ -500,9 +500,15 @@ function twitter_action(App $a, $uid, $pid, $action)
|
||||||
break;
|
break;
|
||||||
case 'like':
|
case 'like':
|
||||||
$result = $connection->post('favorites/create', $post);
|
$result = $connection->post('favorites/create', $post);
|
||||||
|
if ($connection->getLastHttpCode() != 200) {
|
||||||
|
Logger::error('Unable to create favorite', ['result' => $result]);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'unlike':
|
case 'unlike':
|
||||||
$result = $connection->post('favorites/destroy', $post);
|
$result = $connection->post('favorites/destroy', $post);
|
||||||
|
if ($connection->getLastHttpCode() != 200) {
|
||||||
|
Logger::error('Unable to destroy favorite', ['result' => $result]);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Logger::warning('Unhandled action', ['action' => $action]);
|
Logger::warning('Unhandled action', ['action' => $action]);
|
||||||
|
@ -1048,9 +1054,8 @@ function twitter_get_relation($uid, $target, $contact = [])
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$status = $connection->get('friendships/show', $parameters);
|
$status = $connection->get('friendships/show', $parameters);
|
||||||
} catch (TwitterOAuthException $e) {
|
if ($connection->getLastHttpCode() !== 200) {
|
||||||
Logger::info('Error fetching friendship status', ['user' => $uid, 'target' => $target, 'message' => $e->getMessage()]);
|
throw new Exception($status->errors[0]->message ?? 'HTTP response code ' . $connection->getLastHttpCode(), $status->errors[0]->code ?? $connection->getLastHttpCode());
|
||||||
return $relation;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$following = $status->relationship->source->following;
|
$following = $status->relationship->source->following;
|
||||||
|
@ -1067,6 +1072,9 @@ function twitter_get_relation($uid, $target, $contact = [])
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::info('Fetched friendship relation', ['user' => $uid, 'target' => $target, 'relation' => $relation]);
|
Logger::info('Fetched friendship relation', ['user' => $uid, 'target' => $target, 'relation' => $relation]);
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
Logger::error('Error fetching friendship status', ['user' => $uid, 'target' => $target, 'message' => $e->getMessage()]);
|
||||||
|
}
|
||||||
|
|
||||||
return $relation;
|
return $relation;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user