Skip to content

Commit 8f80716

Browse files
author
Ron Dahlgren
committed
Decode is a symbol, not a string
1 parent 6c04a55 commit 8f80716

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

lib/serpapi/error.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# frozen_string_literal: true
33

44
module SerpApi
5-
class Error < StandardError
5+
class SerpApiError < StandardError
66
attr_reader :serpapi_error, :search_params, :response_status, :search_id, :decoder
77

88
# All attributes are optional keyword arguments.
@@ -25,7 +25,7 @@ def initialize(message = nil,
2525
@search_params = freeze_hash(search_params)
2626
@response_status = validate_optional_integer(response_status, :response_status)
2727
@search_id = validate_optional_string(search_id, :search_id)
28-
@decoder = validate_optional_string(decoder, :decoder)
28+
@decoder = validate_optional_symbol(decoder, :decoder)
2929
end
3030

3131
# Return a compact hash representation (omits nil values).
@@ -65,6 +65,14 @@ def validate_optional_integer(value, name = nil)
6565
end
6666
end
6767

68+
def validate_optional_symbol(value, name = nil)
69+
return nil if value.nil?
70+
unless value.is_a?(Symbol)
71+
raise TypeError, "expected #{name || 'value'} to be a Symbol, got #{value.class}"
72+
end
73+
value.freeze
74+
end
75+
6876
def freeze_hash(value)
6977
return nil if value.nil?
7078
unless value.is_a?(Hash)

0 commit comments

Comments
 (0)