This repository has been archived by the owner on Mar 21, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(error): Display human error when API key ACL is not enough
- Loading branch information
1 parent
82e65af
commit 7870f2c
Showing
21 changed files
with
378 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,7 @@ | ||
group :jekyll_v3 do | ||
guard :rspec, cmd: 'appraisal jekyll-v3 bundle exec rspec --color --format documentation' do | ||
watch(%r{^spec/.+_spec\.rb$}) | ||
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } | ||
watch('spec/spec_helper.rb') { 'spec' } | ||
end | ||
end | ||
|
||
group :jekyll_v2 do | ||
guard :rspec, cmd: 'appraisal jekyll-v2 bundle exec rspec --color --format documentation' do | ||
watch(%r{^spec/.+_spec\.rb$}) | ||
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } | ||
watch('spec/spec_helper.rb') { 'spec' } | ||
end | ||
guard :rspec, cmd: 'bundle exec rspec --color --format documentation' do | ||
watch(%r{^spec/.+_spec\.rb$}) | ||
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } | ||
watch('spec/spec_helper.rb') { 'spec' } | ||
end | ||
|
||
notification :off |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
require 'json' | ||
require 'verbal_expressions' | ||
|
||
# Helps in displaying useful error messages to users, to help them debug their | ||
# issues | ||
class AlgoliaSearchErrorHandler | ||
# Will output the specified error file. | ||
# First line is displayed as error, next ones as warning | ||
def display(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 | ||
|
||
def error_tester | ||
VerEx.new do | ||
find 'Cannot ' | ||
capture('verb') { word } | ||
find ' to ' | ||
capture('scheme') { word } | ||
find '://' | ||
capture('app_id') { word } | ||
anything_but '/' | ||
find '/' | ||
capture('api_version') { digit } | ||
find '/' | ||
capture('api_section') { word } | ||
find '/' | ||
capture('index_name') { word } | ||
find '/' | ||
capture('api_action') { word } | ||
find ': ' | ||
capture('json') do | ||
find '{' | ||
anything_but('}') | ||
find '}' | ||
end | ||
find ' (' | ||
capture('http_error') { word } | ||
find ')' | ||
end | ||
end | ||
|
||
def parse_algolia_error(error) | ||
error.gsub!("\n", '') | ||
|
||
tester = error_tester | ||
matches = tester.match(error) | ||
|
||
return false unless matches | ||
|
||
hash = {} | ||
matches.names.each do |match| | ||
hash[match] = matches[match] | ||
end | ||
|
||
# Cast integers | ||
hash['api_version'] = hash['api_version'].to_i | ||
hash['http_error'] = hash['http_error'].to_i | ||
|
||
# Parse JSON | ||
hash['json'] = JSON.parse(hash['json']) | ||
|
||
hash | ||
end | ||
|
||
# Given an Algolia API error message, will return the best error message | ||
def readable_algolia_error(error) | ||
error = parse_algolia_error(error) | ||
return false unless error | ||
|
||
# Given API key does not have rights on the _tmp index | ||
if error['http_error'] == 403 && error['index_name'] =~ /_tmp$/ | ||
return 'check_key_acl_to_tmp_index' | ||
end | ||
|
||
false | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env bash | ||
|
||
COVERAGE=1 appraisal jekyll-v2 bundle exec rspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,4 @@ | |
# worrying about appraisal | ||
cd "$(dirname "$BASH_SOURCE")"/.. | ||
|
||
bundle exec rspec | ||
COVERAGE=1 bundle exec rspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/usr/bin/env bash | ||
cd "$(dirname "$BASH_SOURCE")"/.. | ||
|
||
guard -g jekyll_v2 | ||
appraisal jekyll-v2 guard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/usr/bin/env bash | ||
cd "$(dirname "$BASH_SOURCE")"/.. | ||
|
||
guard -g jekyll_v3 | ||
appraisal jekyll-v3 guard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.