Exception: Fanforce::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Fanforce::Error
show all
- Includes:
- Utils
- Defined in:
- lib/fanforce/errors/errors.rb
Defined Under Namespace
Classes: AddonFailed, BadRequest, Forbidden, InternalError, NotFound, RequestFailed, Unauthorized, WebhookFailed
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(*errors) ⇒ Error
Returns a new instance of Error.
11
12
13
14
15
16
17
18
|
# File 'lib/fanforce/errors/errors.rb', line 11
def initialize(*errors)
if errors[0].is_a?(String) and errors[1].is_a?(Hash) and is_blank?(errors[1][:message])
tmp = errors.shift() and errors[0][:message] = tmp
end
@public_errors = format_errors(errors)
@env = Fanforce.env
super(default_message.to_s)
end
|
Instance Attribute Details
#env ⇒ Object
Returns the value of attribute env.
5
6
7
|
# File 'lib/fanforce/errors/errors.rb', line 5
def env
@env
end
|
#public_errors ⇒ Object
Returns the value of attribute public_errors.
5
6
7
|
# File 'lib/fanforce/errors/errors.rb', line 5
def public_errors
@public_errors
end
|
Instance Method Details
#code ⇒ Object
40
|
# File 'lib/fanforce/errors/errors.rb', line 40
def code; 500 end
|
#curl_command ⇒ Object
35
36
37
38
|
# File 'lib/fanforce/errors/errors.rb', line 35
def curl_command
return nil if is_blank?(@env[:request_method]) or is_blank?(@env[:request_url])
Fanforce::Utils.curl_command(@env[:request_method], @env[:request_url], @env[:request_params])
end
|
#default_error_code ⇒ Object
43
|
# File 'lib/fanforce/errors/errors.rb', line 43
def default_error_code; end
|
#default_message ⇒ Object
41
|
# File 'lib/fanforce/errors/errors.rb', line 41
def default_message; end
|
#for(*args) ⇒ Object
7
8
9
|
# File 'lib/fanforce/errors/errors.rb', line 7
def for(*args)
self.new(*args)
end
|
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/fanforce/errors/errors.rb', line 24
def format_error(raw_error)
return {message: is_blank?(raw_error) ? default_message : raw_error.to_s} if !raw_error.is_a?(Hash)
raw_error = symbolize_keys(raw_error)
error = { message: is_blank?(raw_error[:message]) ? default_message : raw_error[:message].to_s }
error[:resource] = raw_error[:resource].to_s if is_present?(raw_error[:resource])
error[:code] = (is_blank?(raw_error[:code]) or !valid_error_codes.include? raw_error[:code].to_sym) ? default_error_code : raw_error[:code].to_s
error[:field] = raw_error[:field].to_s if is_present?(raw_error[:field])
error[:fields] = raw_error[:fields].map {|f| f.to_s } if is_present?(raw_error[:fields])
error
end
|
20
21
22
|
# File 'lib/fanforce/errors/errors.rb', line 20
def format_errors(raw_errors)
raw_errors.is_a?(Array) ? raw_errors.inject([]) {|errors, e| errors << format_error(e) } : [format_error(raw_errors)]
end
|
#valid_error_codes ⇒ Object
42
|
# File 'lib/fanforce/errors/errors.rb', line 42
def valid_error_codes; [] end
|