Class: EVSS::Service
- Inherits:
-
Common::Client::Base
- Object
- Common::Client::Base
- EVSS::Service
- Includes:
- Common::Client::Concerns::Monitoring
- Defined in:
- lib/evss/service.rb
Direct Known Subclasses
Dependents::Service, DisabilityCompensationForm::Service, IntentToFile::Service, Letters::DownloadService, Letters::Service, PCIU::Service, PCIUAddress::Service, PPIU::Service, ReferenceData::Service, VSOSearch::Service
Constant Summary collapse
- STATSD_KEY_PREFIX =
'api.evss'
Instance Attribute Summary collapse
-
#transaction_id ⇒ Object
readonly
Returns the value of attribute transaction_id.
Class Method Summary collapse
Instance Method Summary collapse
- #handle_error(error) ⇒ Object private
- #headers ⇒ Object
-
#initialize(user = nil, auth_headers = nil) ⇒ Service
constructor
A new instance of Service.
- #perform(method, path, body = nil, headers = {}, options = {}) ⇒ Object
- #save_error_details(error) ⇒ Object private
- #with_monitoring_and_error_handling ⇒ Object private
Methods included from Common::Client::Concerns::Monitoring
#increment, #increment_failure, #increment_total, #with_monitoring
Methods inherited from Common::Client::Base
#config, configuration, #connection, #delete, #get, #post, #put, #raise_backend_exception, #raise_not_authenticated, #request, #sanitize_headers!, #service_name
Methods included from SentryLogging
#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata
Constructor Details
#initialize(user = nil, auth_headers = nil) ⇒ Service
Returns a new instance of Service.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/evss/service.rb', line 13 def initialize(user = nil, auth_headers = nil) @user = user if auth_headers.nil? @headers = EVSS::AuthHeaders.new(user) @transaction_id = @headers.transaction_id else @headers = auth_headers @transaction_id = auth_headers['va_eauth_service_transaction_id'] end end |
Instance Attribute Details
#transaction_id ⇒ Object (readonly)
Returns the value of attribute transaction_id.
8 9 10 |
# File 'lib/evss/service.rb', line 8 def transaction_id @transaction_id end |
Class Method Details
.service_is_up? ⇒ Boolean
33 34 35 36 37 38 39 40 |
# File 'lib/evss/service.rb', line 33 def self.service_is_up? last_evss_claims_outage = Breakers::Outage.find_latest(service: EVSS::ClaimsService.breakers_service) evss_claims_up = last_evss_claims_outage.blank? || last_evss_claims_outage.end_time.present? last_evss_common_outage = Breakers::Outage.find_latest(service: EVSS::CommonService.breakers_service) evss_common_up = last_evss_common_outage.blank? || last_evss_common_outage.end_time.present? evss_claims_up && evss_common_up end |
Instance Method Details
#handle_error(error) ⇒ Object (private)
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/evss/service.rb', line 61 def handle_error(error) Sentry.set_extras( message: error., url: config.base_path, transaction_id: @transaction_id ) case error when Faraday::ParsingError raise_backend_exception('EVSS502', self.class) when Common::Client::Errors::ClientError Sentry.set_extras(body: error.body) raise Common::Exceptions::Forbidden if error.status == 403 raise_backend_exception('EVSS400', self.class, error) if error.status == 400 raise_backend_exception('EVSS502', self.class, error) else raise error end end |
#headers ⇒ Object
29 30 31 |
# File 'lib/evss/service.rb', line 29 def headers { 'Content-Type' => 'application/json' } end |
#perform(method, path, body = nil, headers = {}, options = {}) ⇒ Object
24 25 26 27 |
# File 'lib/evss/service.rb', line 24 def perform(method, path, body = nil, headers = {}, = {}) merged_headers = @headers.to_h.merge(headers) super(method, path, body, merged_headers, ) end |
#save_error_details(error) ⇒ Object (private)
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/evss/service.rb', line 50 def save_error_details(error) Sentry.(external_service: self.class.to_s.underscore) Sentry.set_extras( url: config.base_path, message: error., body: error.body, transaction_id: @transaction_id ) end |
#with_monitoring_and_error_handling ⇒ Object (private)
44 45 46 47 48 |
# File 'lib/evss/service.rb', line 44 def with_monitoring_and_error_handling(&) with_monitoring(2, &) rescue => e handle_error(e) end |