diff options
| author | Teddy Wing | 2016-09-12 19:33:45 -0400 |
|---|---|---|
| committer | Teddy Wing | 2016-09-12 19:33:45 -0400 |
| commit | d3bce36482e720ae21b2993b6a8933cf82d7b082 (patch) | |
| tree | b9f2daadd4ecc1479d4cd7e6f76c2aa239a77866 | |
| parent | ccb58bce6a0bef02ebdc238cace78b4a8cd1a0c9 (diff) | |
| download | irssi-slack-profile-d3bce36482e720ae21b2993b6a8933cf82d7b082.tar.bz2 | |
slack_api: Move `die`s outside the subroutine
Don't cause the command to break WHOIS output. Previously when we were
only using it to call the 'users.list' Slack API method it was fine
because the WHOIS output didn't directly depend on fetching the entire
users list (since we have a cache).
Now that we query the Slack API on each `/swhois` (the
'users.profile.get' method), we don't want to break profile output that
can easily come from our cached data by dying. There's still value in
displaying profile information without custom fields.
We remove the `die` calls from `slack_api` and change them to a single
`die` in the `fetch_users_list` method, since if this fails we really do
want to stop script execution. In that case, if we don't get the users
list back from the API, we can't set it to our in-memory cache nor store
it to our cache file.
| -rw-r--r-- | slack_profile.pl | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/slack_profile.pl b/slack_profile.pl index f6eadff..6d5b9d2 100644 --- a/slack_profile.pl +++ b/slack_profile.pl @@ -112,19 +112,19 @@ sub slack_api { } else { Irssi::print("Error from the Slack API: $payload->{'error'}"); - die 'Unable to retrieve data from the Slack API'; } } else { Irssi::print("Error calling the Slack API: ($resp->{'status'}) $resp->{'reason'} | $resp->{'content'}"); - die 'Unable to communicate with the Slack API'; } } sub fetch_users_list { Irssi::print('Fetching users list from Slack. This could take a while...'); - my $resp = slack_api('users.list'); + my $resp = slack_api('users.list') or + die 'Unable to retrieve users from the Slack API'; + @users_list = @{$resp->{'members'}}; store \@users_list, users_list_cache; } |
