Class: EVSS::DisabilityCompensationForm::Service

Inherits:
Service show all
Defined in:
lib/evss/disability_compensation_form/service.rb

Overview

Proxy Service for EVSS’s 526 endpoints. A set of VAAFI headers generated from user data must be passed on initialization so that the calls can be authenticated. The disability compensation service requires additional headers so EVSS::DisabilityCompensationAuthHeaders is used to decorate the default EVSS headers AuthHeaders.

Examples:

Create a service

auth_headers = EVSS::AuthHeaders.new(@current_user).to_h
disability_auth_headers = EVSS::DisabilityCompensationAuthHeaders.new(@current_user).add_headers(auth_headers)
EVSS::DisabilityCompensationForm::Service.new(disability_auth_headers)

Direct Known Subclasses

Dvp::Service, NonBreakeredService

Constant Summary

Constants inherited from Service

Service::STATSD_KEY_PREFIX

Instance Attribute Summary

Attributes inherited from Service

#transaction_id

Instance Method Summary collapse

Methods inherited from Service

#headers, #perform, #save_error_details, service_is_up?, #with_monitoring_and_error_handling

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, #perform, #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(headers) ⇒ Service

Returns a new instance of Service.

Parameters:



29
30
31
32
# File 'lib/evss/disability_compensation_form/service.rb', line 29

def initialize(headers)
  @headers = headers
  @transaction_id = @headers['va_eauth_service_transaction_id']
end

Instance Method Details

#get_form526(form_content) ⇒ Faraday::Response

Gets a filled out 526ez PDF from EVSS from the same playload of the submit endpoint. Returns PDF stream in response, instead of submitting to auto-establish. This is used in the 526ez backup submission process when auto-establisment errors and is not possible.

Parameters:

Returns:

  • (Faraday::Response)
    • Response from EVSS /getPDF endpoint



72
73
74
75
76
77
78
# File 'lib/evss/disability_compensation_form/service.rb', line 72

def get_form526(form_content)
  with_monitoring_and_error_handling do
    headers = { 'Content-Type' => 'application/json' }
    options = { timeout: Settings.evss.disability_compensation_form.submit_timeout || 355 }
    perform(:post, 'getPDF', form_content, headers, options)
  end
end

#get_rated_disabilitiesEVSS::DisabilityCompensationForm::RatedDisabilitiesResponse

GETs a user’s rated disabilities

Returns:



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/evss/disability_compensation_form/service.rb', line 38

def get_rated_disabilities
  if @headers['va_eauth_birlsfilenumber'].blank?
    Rails.logger.info('Missing `birls_id`', edipi: @headers['va_eauth_dodedipnid'])
  end
  with_monitoring_and_error_handling do
    Rails.cache.fetch("evss_rated_disabilities/#{@headers['va_eauth_dodedipnid']}-#{@headers['va_eauth_pnid']}",
                      expires_in: 30.minutes) do
      raw_response = perform(:get, 'ratedDisabilities')
      RatedDisabilitiesResponse.new(raw_response.status, raw_response)
    end
  end
end

#handle_error(error) ⇒ Object (private)



96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/evss/disability_compensation_form/service.rb', line 96

def handle_error(error)
  handle_service_unavailable_error(error)

  # Common::Client::Errors::ClientError is raised from Common::Client::Base#request after it rescues
  # Faraday::ClientError.  EVSS::ErrorMiddleware::EVSSError is raised from EVSS::ErrorMiddleware when
  # there is a 200-response with an error message in the body
  if ((error.is_a?(Common::Client::Errors::ClientError) && error.status != 403) ||
     error.is_a?(EVSS::ErrorMiddleware::EVSSError)) && error.body.is_a?(Hash)
    save_error_details(error) # Sentry extra_context
    raise EVSS::DisabilityCompensationForm::ServiceException, error.body
  else
    super(error)
  end
end

#handle_service_unavailable_error(error) ⇒ Object (private)



90
91
92
93
94
# File 'lib/evss/disability_compensation_form/service.rb', line 90

def handle_service_unavailable_error(error)
  if error.is_a?(Common::Client::Errors::ClientError) && error.status == 503
    raise EVSS::DisabilityCompensationForm::ServiceUnavailableException
  end
end

#submit_form526(form_content) ⇒ EVSS::DisabilityCompensationForm::FormSubmitResponse

POSTs a 526 form to the EVSS submit endpoint. EVSS is bound to VBMSs response times and, therefore, the timeout has to be extended to ~6 minutes to match their upstream timeout.

Parameters:

Returns:



57
58
59
60
61
62
63
64
# File 'lib/evss/disability_compensation_form/service.rb', line 57

def submit_form526(form_content)
  with_monitoring_and_error_handling do
    headers = { 'Content-Type' => 'application/json' }
    options = { timeout: Settings.evss.disability_compensation_form.submit_timeout || 355 }
    raw_response = perform(:post, 'submit', form_content, headers, options)
    FormSubmitResponse.new(raw_response.status, raw_response)
  end
end

#validate_form526(form_content) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/evss/disability_compensation_form/service.rb', line 80

def validate_form526(form_content)
  with_monitoring_and_error_handling do
    headers = { 'Content-Type' => 'application/json' }
    options = { timeout: Settings.evss.disability_compensation_form.submit_timeout || 355 }
    perform(:post, 'validate', form_content, headers, options)
  end
end