Class: VAProfile::Service
Constant Summary
collapse
- STATSD_KEY_PREFIX =
VAProfile::Stats::STATSD_KEY_PREFIX
Class Method Summary
collapse
Instance Method Summary
collapse
#config, configuration, #connection, #delete, #get, #post, #put, #raise_not_authenticated, #request, #sanitize_headers!, #service_name
#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata
Constructor Details
#initialize(user) ⇒ Service
Returns a new instance of Service.
15
16
17
|
# File 'lib/va_profile/service.rb', line 15
def initialize(user)
@user = user
end
|
Class Method Details
.breakers_service ⇒ Object
27
28
29
|
# File 'lib/va_profile/service.rb', line 27
def self.breakers_service
Common::Client::Base.breakers_service
end
|
Instance Method Details
#final_failure?(error) ⇒ Boolean
84
85
86
|
# File 'lib/va_profile/service.rb', line 84
def final_failure?(error)
%w[COMPLETED_FAILURE REJECTED].include? error.body&.dig('status')
end
|
#handle_error(error) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/va_profile/service.rb', line 43
def handle_error(error)
case error
when Common::Client::Errors::ParsingError Sentry.(
message: error.message,
url: config.base_path
)
raise_backend_exception('VET360_502', self.class)
when Common::Client::Errors::ClientError
save_error_details(error)
raise Common::Exceptions::Forbidden if error.status == 403
raise_invalid_body(error, self.class) unless error.body.is_a?(Hash)
code = parse_messages(error)&.first.try(:[], 'code')
raise_backend_exception("VET360_#{code}", self.class, error) if code.present?
raise_backend_exception('VET360_502', self.class, error)
else
raise error
end
end
|
#log_dates(body) ⇒ Object
33
34
35
36
37
38
39
40
41
|
# File 'lib/va_profile/service.rb', line 33
def log_dates(body)
parsed_body = JSON.parse(body)
Sentry.(
request_dates: parsed_body['bio'].slice('effectiveStartDate', 'effectiveEndDate', 'sourceDate')
)
rescue
nil
end
|
#parse_messages(error) ⇒ Object
88
89
90
91
|
# File 'lib/va_profile/service.rb', line 88
def parse_messages(error)
messages = error.body&.dig('messages')
messages&.map { |m| VAProfile::Models::Message.build_from(m) }
end
|
19
20
21
22
23
24
25
|
# File 'lib/va_profile/service.rb', line 19
def perform(method, path, body = nil, = {})
log_dates(body)
VAProfile::Stats.increment('total_operations')
config..merge()
super(method, path, body, )
end
|
#person_transaction?(error) ⇒ Boolean
80
81
82
|
# File 'lib/va_profile/service.rb', line 80
def person_transaction?(error)
error&.backtrace&.join(',')&.include? 'get_person_transaction_status'
end
|
#person_transaction_failure?(error) ⇒ Boolean
76
77
78
|
# File 'lib/va_profile/service.rb', line 76
def person_transaction_failure?(error)
person_transaction?(error) && final_failure?(error)
end
|
#raise_backend_exception(key, source, error = nil) ⇒ Object
93
94
95
96
|
# File 'lib/va_profile/service.rb', line 93
def raise_backend_exception(key, source, error = nil)
report_stats_on(key)
super
end
|
#raise_invalid_body(error, source) ⇒ Object
#report_stats_on(exception_key) ⇒ Object
109
110
111
112
113
114
115
|
# File 'lib/va_profile/service.rb', line 109
def report_stats_on(exception_key)
if VAProfile::Exceptions::Parser.instance.known?(exception_key)
VAProfile::Stats.increment_exception(exception_key)
else
log_message_to_sentry('New VAProfile Exceptions Key', :info, key: exception_key)
end
end
|
#save_error_details(error) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/va_profile/service.rb', line 64
def save_error_details(error)
Sentry.(
message: error.message,
url: config.base_path,
body: error.body
)
Sentry.set_tags(
va_profile: person_transaction_failure?(error) ? 'failed_vet360_id_initializations' : 'general_client_error'
)
end
|