Skip to content

Commit fbf3910

Browse files
committed
addressing comments
1 parent 975bf84 commit fbf3910

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

lib/optimizely.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,13 @@ def initialize(datafile, event_dispatcher = nil, logger = nil, error_handler = n
6464

6565
begin
6666
@config = ProjectConfig.new(datafile, @logger, @error_handler)
67-
rescue InvalidDatafileVersionError => e
67+
rescue StandardError => e
6868
@is_valid = false
6969
@logger = SimpleLogger.new
70-
@logger.log(Logger::ERROR, e.message)
71-
return
72-
rescue
73-
@is_valid = false
74-
@logger = SimpleLogger.new
75-
@logger.log(Logger::ERROR, InvalidInputError.new('datafile').message)
70+
error_msg = e.class == InvalidDatafileVersionError ? e.message : InvalidInputError.new('datafile').message
71+
error_to_handle = e.class == InvalidDatafileVersionError ? InvalidDatafileVersionError : InvalidInputError
72+
@logger.log(Logger::ERROR, error_msg)
73+
@error_handler.handle_error error_to_handle
7674
return
7775
end
7876

spec/project_spec.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,11 @@ class InvalidErrorHandler; end
110110
Optimizely::Project.new(config_body_JSON, nil, nil, nil, true)
111111
end
112112

113-
it 'should log an error when provided a datafile that is not JSON and skip_json_validation is true' do
113+
it 'should log and raise an error when provided a datafile that is not JSON and skip_json_validation is true' do
114114
expect_any_instance_of(Optimizely::SimpleLogger).to receive(:log).once.with(Logger::ERROR, 'Provided datafile is in an invalid format.')
115+
expect_any_instance_of(Optimizely::RaiseErrorHandler).to receive(:handle_error).once.with(Optimizely::InvalidInputError)
115116

116-
Optimizely::Project.new('this is not JSON', nil, nil, nil, true)
117+
Optimizely::Project.new('this is not JSON', nil, nil, Optimizely::RaiseErrorHandler.new, true)
117118
end
118119

119120
it 'should log an error when provided an invalid JSON datafile and skip_json_validation is true' do
@@ -122,11 +123,12 @@ class InvalidErrorHandler; end
122123
Optimizely::Project.new('{"version": "2", "foo": "bar"}', nil, nil, nil, true)
123124
end
124125

125-
it 'should log an error when provided a datafile of unsupported version' do
126+
it 'should log and raise an error when provided a datafile of unsupported version' do
126127
config_body_invalid_json = JSON.parse(config_body_invalid_JSON)
127128
expect_any_instance_of(Optimizely::SimpleLogger).to receive(:log).once.with(Logger::ERROR, "This version of the Ruby SDK does not support the given datafile version: #{config_body_invalid_json['version']}.")
129+
expect_any_instance_of(Optimizely::RaiseErrorHandler).to receive(:handle_error).once.with(Optimizely::InvalidDatafileVersionError)
128130

129-
Optimizely::Project.new(config_body_invalid_JSON, nil, nil, nil, true)
131+
Optimizely::Project.new(config_body_invalid_JSON, nil, nil, Optimizely::RaiseErrorHandler.new, true)
130132
end
131133
end
132134

0 commit comments

Comments
 (0)