feat(errors): Moved error messages to txt files

This commit is contained in:
Pixelastic 2015-07-20 11:45:28 +02:00
parent eaba4c42aa
commit 81227c0207
5 changed files with 37 additions and 26 deletions

View File

@ -7,6 +7,7 @@ gem 'nokogiri', '~> 1.6'
group :development do
gem 'coveralls', '~> 0.8'
gem 'flay', '~> 2.6'
gem 'flog', '~> 4.3'
gem 'guard-rspec', '~> 4.6'
gem 'jekyll', '~> 2.5' # Jekyll custom commands only available from 2.5

View File

@ -24,47 +24,36 @@ class AlgoliaSearchCredentialChecker
nil
end
def display_error(file)
file = File.expand_path(File.join(File.dirname(__FILE__), '../txt', file))
content = File.open(file).readlines.map(&:chomp)
content.each_with_index do |line, index|
if index == 0
Jekyll.logger.error line
next
end
Jekyll.logger.warn line
end
end
# Check that the API key is available
def check_api_key
return if api_key
Jekyll.logger.error 'Algolia Error: No API key defined'
Jekyll.logger.warn ' You have two ways to configure your API key:'
Jekyll.logger.warn ' - The ALGOLIA_API_KEY environment variable'
Jekyll.logger.warn ' - A file named ./_algolia_api_key in your '\
'source folder'
display_error('api_key_missing')
exit 1
end
# Check that the application id is defined
def check_application_id
return if @config['algolia'] && @config['algolia']['application_id']
Jekyll.logger.error 'Algolia Error: No application ID defined'
Jekyll.logger.warn ' Please set your application id in the '\
'_config.yml file, like so:'
Jekyll.logger.warn ''
# The spaces are needed otherwise the text is centered
Jekyll.logger.warn ' algolia: '
Jekyll.logger.warn ' application_id: \'{your_application_id}\''
Jekyll.logger.warn ''
Jekyll.logger.warn ' Your application ID can be found in your algolia'\
' dashboard'
Jekyll.logger.warn ' https://www.algolia.com/licensing'
display_error('application_id_missing')
exit 1
end
# Check that the index name is defined
def check_index_name
return if @config['algolia'] && @config['algolia']['index_name']
Jekyll.logger.error 'Algolia Error: No index name defined'
Jekyll.logger.warn ' Please set your index name in the _config.yml'\
' file, like so:'
Jekyll.logger.warn ''
# The spaces are needed otherwise the text is centered
Jekyll.logger.warn ' algolia: '
Jekyll.logger.warn ' index_name: \'{your_index_name}\''
Jekyll.logger.warn ''
Jekyll.logger.warn ' You can edit your indices in your dashboard'
Jekyll.logger.warn ' https://www.algolia.com/explorer'
display_error('index_name_missing')
exit 1
end

4
txt/api_key_missing Normal file
View File

@ -0,0 +1,4 @@
Algolia Error: No API key defined
You have two ways to configure your API key:
- The ALGOLIA_API_KEY environment variable
- A file named _algolia_api_key in your source folder

View File

@ -0,0 +1,8 @@
Algolia Error: No application ID defined
Please set your application id in the _config.yml file, like so:
algolia:
application_id: {your_application_id}
Your application ID can be found in your algolia dashboard:
https://www.algolia.com/licensing

9
txt/index_name_missing Normal file
View File

@ -0,0 +1,9 @@
Algolia Error: No index name defined
Please set your index name in the _config.yml file, like so:
algolia:
index_name: {your_index_name}
You can edit your indices in your dashboard:
https://www.algolia.com/explorer