def run(command, args, retries=0)
Heroku::Plugin.load!
begin
run_internal 'auth:reauthorize', args.dup if retries > 0
run_internal(command, args.dup)
rescue InvalidCommand
error "Unknown command. Run 'heroku help' for usage information."
rescue RestClient::Unauthorized
if retries < 3
STDERR.puts "Authentication failure"
run(command, args, retries+1)
else
error "Authentication failure"
end
rescue RestClient::ResourceNotFound => e
error extract_not_found(e.http_body)
rescue RestClient::RequestFailed => e
error extract_error(e.http_body) unless e.http_code == 402
retry if run_internal('account:confirm_billing', args.dup)
rescue RestClient::RequestTimeout
error "API request timed out. Please try again, or contact support@heroku.com if this issue persists."
rescue CommandFailed => e
error e.message
rescue Interrupt => e
error "\n[canceled]"
end
end