Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/intercom/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ def to_hash
# Check that you have set Intercom.token correctly.
class AuthenticationError < IntercomError; end

# Raised when the token provided is linked to a deleted application.
class AppSuspendedError < AuthenticationError; end

# Raised when the token provided has been revoked.
class TokenRevokedError < AuthenticationError; end

# Raised when the token provided can't be decoded, and is most likely invalid.
class TokenUnauthorizedError < AuthenticationError; end

# Raised when something goes wrong on within the Intercom API service.
class ServerError < IntercomError; end

Expand Down
6 changes: 6 additions & 0 deletions lib/intercom/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ def raise_application_errors_on_failure(error_list_details, http_code)
case error_code
when 'unauthorized', 'forbidden', 'token_not_found'
raise Intercom::AuthenticationError.new(error_details['message'], error_context)
when 'token_suspended'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want add a check for token_unauthorized and token_revoked too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good shout, my bad!

raise Intercom::AppSuspendedError.new(error_details['message'], error_context)
when 'token_revoked'
raise Intercom::TokenRevokedError.new(error_details['message'], error_context)
when 'token_unauthorized'
raise Intercom::TokenUnauthorizedError.new(error_details['message'], error_context)
when "bad_request", "missing_parameter", 'parameter_invalid', 'parameter_not_found'
raise Intercom::BadRequestError.new(error_details['message'], error_context)
when "not_restorable"
Expand Down