Skip to content

Commit

Permalink
Improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Feb 26, 2013
1 parent 14d34cf commit 00ca2bf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -63,7 +63,7 @@ previously registered a Twitter application, it should be listed at
to set your application's Access Level to "Read, Write and Access direct
messages", otherwise you'll receive an error that looks like this:

Read-only application cannot POST
Error processing your OAuth request: Read-only application cannot POST

Now, you're ready to authorize a Twitter account with your application. To
proceed, type the following command at the prompt and follow the instructions:
Expand Down
20 changes: 17 additions & 3 deletions bin/t
Expand Up @@ -10,7 +10,9 @@ require 'twitter'

# Output message to $stderr, prefixed with the program name
def pute(*args)
args.first.insert(0, "#{$0}: ")
first = args.shift.dup
first.insert(0, "#{$0}: ")
args.unshift(first)
$stderr.puts(*args)
end

Expand All @@ -27,8 +29,20 @@ rescue Twitter::Error::TooManyRequests => error
"The rate limit for this request will reset in #{error.rate_limit.reset_in} seconds.",
"While you wait, consider making a polite request for Twitter to increase the API rate limit at https://dev.twitter.com/discussions/10644"
exit 1
rescue Twitter::Error::Unauthorized => error
pute error.message, "Run `t authorize` to authorize."
rescue Twitter::Error::BadRequest => error
pute error.message,
"Run `t authorize` to authorize."
exit 1
rescue Twitter::Error::Forbidden, Twitter::Error::Unauthorized => error
pute error.message
if error.message == "Error processing your OAuth request: Read-only application cannot POST" ||
error.message == "This application is not allowed to access or delete your direct messages"
$stderr.puts(%q(Make sure to set your Twitter application's Access Level to "Read, Write and Access direct messages".))
require 'thor'
Thor::Shell::Basic.new.ask "Press [Enter] to open the Twitter Developer site."
require 'launchy'
Launchy.open("https://dev.twitter.com/apps")
end
exit 1
rescue Twitter::Error => error
pute error.message
Expand Down

1 comment on commit 00ca2bf

@nmeum
Copy link

@nmeum nmeum commented on 00ca2bf Mar 22, 2013

Choose a reason for hiding this comment

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

Y U NO Kernel#abort?

Please sign in to comment.