Class: Solrengine::Programs::ErrorMapper
- Inherits:
-
Object
- Object
- Solrengine::Programs::ErrorMapper
- Defined in:
- lib/solrengine/programs/error_mapper.rb
Constant Summary collapse
- ANCHOR_ERROR_OFFSET =
6000
Class Method Summary collapse
-
.extract_custom_error(rpc_error) ⇒ Object
Extract custom error code from an RPC InstructionError response Example: href="0,{"Custom":6001">InstructionError”:}.
Instance Method Summary collapse
-
#initialize(parsed_errors) ⇒ ErrorMapper
constructor
A new instance of ErrorMapper.
- #map(error_code) ⇒ Object
- #raise_if_program_error!(rpc_error) ⇒ Object
Constructor Details
#initialize(parsed_errors) ⇒ ErrorMapper
Returns a new instance of ErrorMapper.
6 7 8 9 10 |
# File 'lib/solrengine/programs/error_mapper.rb', line 6 def initialize(parsed_errors) @errors_by_code = parsed_errors.each_with_object({}) do |err, h| h[err.code] = err end end |
Class Method Details
.extract_custom_error(rpc_error) ⇒ Object
Extract custom error code from an RPC InstructionError response Example: href="0,{"Custom":6001">InstructionError”:}
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/solrengine/programs/error_mapper.rb', line 21 def self.extract_custom_error(rpc_error) return nil unless rpc_error.is_a?(Hash) instruction_error = rpc_error["InstructionError"] return nil unless instruction_error.is_a?(Array) && instruction_error.size == 2 custom = instruction_error[1] return nil unless custom.is_a?(Hash) && custom.key?("Custom") custom["Custom"] end |
Instance Method Details
#map(error_code) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/solrengine/programs/error_mapper.rb', line 12 def map(error_code) err = @errors_by_code[error_code] return nil unless err { code: err.code, name: err.name, message: err. } end |
#raise_if_program_error!(rpc_error) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/solrengine/programs/error_mapper.rb', line 33 def raise_if_program_error!(rpc_error) code = self.class.extract_custom_error(rpc_error) return unless code mapped = map(code) if mapped raise ProgramError.new( code: mapped[:code], error_name: mapped[:name], message: mapped[:message] ) else raise TransactionError, "Program error with unknown code: #{code}" end end |