Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Error handling and user-agent setting. #1

Merged
merged 3 commits into from
Oct 23, 2021

Conversation

alexmv
Copy link

@alexmv alexmv commented Oct 19, 2021

Reference 42wim/matterbridge#1589 -- this is the gozulipbot parts of those changes.

The RegisterEvents method, called from the Connect of the zulip
bridge, never checked the HTTP response code from the server; it would
blindly assume success and shove the JSON it got into the Queue
structure.  This meant that matterbridge would happily make repeated
requests to the server (see subsequent commits) despite initial
registration having failed.

Catch non-200 responses, and (when possible) unravel the
server-supplied error message within that; return as an err.
Zulip servers respond with 401's if the authentication fails (e.g. a
bad token), and 403's if the authenticated user does not have
permission to read something.  403's are thus, unlikely to happen for
this method of consuming the API, and 401's are far more likely.

Include 401 responses in UnauthorizedErrors.
It is good practice for automated bots to identify themselves; the
User-Agent format requires both a name and a version.  This package
does not yet appear to have a concept of release version, so it is
arbitrarily set to `1.0-dev`.
@42wim 42wim merged commit a19d6c1 into matterbridge:work Oct 23, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants