Skip to content

Commit 41dde74

Browse files
committed
Add error message on error when call EvernoteAPI
1 parent a7096d8 commit 41dde74

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

lib/ever2boost/cli.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,5 @@ def import
1010
developer_token = ask('DEVELOPER_TOKEN:')
1111
EvernoteAuthorizer.new(developer_token).import(DEFAULT_OUTPUT_DIR)
1212
end
13-
14-
class << self
15-
def tell(message)
16-
tell(message)
17-
end
18-
end
1913
end
2014
end

lib/ever2boost/evernote_authorizer.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ def initialize(developer_token)
1919
note_store = Evernote::EDAM::NoteStore::NoteStore::Client.new(note_store_protocol)
2020
@developer_token = developer_token
2121
@note_store = note_store
22+
rescue => e
23+
abort_with_message e
2224
end
2325

2426
def fetch_notebook_list
@@ -52,6 +54,7 @@ def fetch_notes(filter)
5254
# Download the all of notes fron Evernote and generate Boostnote storage from it
5355
# TODO: move this method to CLI
5456
def import(output_dir)
57+
puts 'processing...'
5558
FileUtils.mkdir_p(output_dir) unless FileTest.exist?(output_dir)
5659
notebook_list = self.notebook_list
5760

@@ -70,6 +73,19 @@ def import(output_dir)
7073
end
7174
end
7275
end
76+
puts 'Successfully finished!'
77+
rescue => e
78+
abort_with_message e
79+
end
80+
81+
def abort_with_message(exception)
82+
if exception.class == Evernote::EDAM::Error::EDAMUserException
83+
abort "\e[31mError! Confirm your developer token\e[0m"
84+
elsif exception.class == Evernote::EDAM::Error::EDAMSystemException
85+
abort "\e[31mError! You reached EvernoteAPI rate limitation\e[0m"
86+
else
87+
raise exception
88+
end
7389
end
7490
end
7591
end

0 commit comments

Comments
 (0)