Class: DecisionReview::PdfValidation::Service

Inherits:
Common::Client::Base show all
Includes:
Common::Client::Concerns::Monitoring, SentryLogging
Defined in:
lib/decision_review/utilities/pdf_validation/service.rb

Constant Summary collapse

LH_ERROR_KEY =
'errors'
LH_ERROR_DETAIL_KEY =
'detail'
GENERIC_FAILURE_MESSAGE =
'Something went wrong...'

Instance Method Summary collapse

Methods included from Common::Client::Concerns::Monitoring

#increment, #increment_failure, #increment_total, #with_monitoring

Methods included from SentryLogging

#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata

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

Instance Method Details

#validate_pdf_with_lighthouse(file) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/decision_review/utilities/pdf_validation/service.rb', line 20

def validate_pdf_with_lighthouse(file)
  perform(:post, 'uploads/validate_document',
          file.read,
          { 'Content-Type' => 'application/pdf', 'Transfer-Encoding' => 'chunked' })
rescue Common::Client::Errors::ClientError => e
  emsg = 'Decision Review Upload failed PDF validation.'
  validation_failure_detail = e.body[LH_ERROR_KEY].map { |d| d[LH_ERROR_DETAIL_KEY] }.join("\n")
  error_details = { message: emsg, error: e, validation_failure_detail: }
  ::Rails.logger.error(emsg, error_details)
  raise Common::Exceptions::UnprocessableEntity.new(
    detail: validation_failure_detail,
    source: 'FormAttachment.lighthouse_validation.invalid_pdf'
  )
rescue => e
  emsg = 'Decision Review Upload failed with an unexpected failure case. Investigation Required.'
  error_details = { message: emsg, error: e }
  ::Rails.logger.error(emsg, error_details)
  raise Common::Exceptions::UnprocessableEntity.new(
    detail: GENERIC_FAILURE_MESSAGE,
    source: 'FormAttachment.lighthouse_validation.unknown_error'
  )
end