Exception: CentralMail::UploadError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/central_mail/upload_error.rb

Constant Summary collapse

DEFAULT_MESSAGE =
'Internal Server Error'
DOC101 =

DOC1xx errors: client errors, invalid submissions

'Invalid multipart payload'
DOC102 =
'Invalid metadata part'
DOC103 =
'Invalid content part'
DOC104 =
'Upload rejected by upstream system'
DOC105 =
'Invalid or unknown id'
DOC106 =
'Maximum document size exceeded.'
DOC107 =
'Empty payload'
DOC108 =
'Maximum page size exceeded.'
DOC201 =

DOC2xx errors: server errors either local or upstream not unambiguously related to submitted content

'Upload server error. Request will be retried when upstream service is available.'
DOC202 =
'Error during processing by upstream system'
STATSD_UPLOAD_FAIL_KEY =
'api.central_mail.upload.fail'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, code: nil, detail: nil, upstream_http_resp_status: nil, pdf_validator_options: {}) ⇒ UploadError

Returns a new instance of UploadError.



48
49
50
51
52
53
54
55
# File 'lib/central_mail/upload_error.rb', line 48

def initialize(message = nil, code: nil, detail: nil, upstream_http_resp_status: nil, pdf_validator_options: {})
  super(message || UploadError.default_message(code, pdf_validator_options))
  @code = code
  @detail = detail
  @upstream_http_resp_status = upstream_http_resp_status

  StatsD.increment self.class::STATSD_UPLOAD_FAIL_KEY, tags: ["status:#{code}"]
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



8
9
10
# File 'lib/central_mail/upload_error.rb', line 8

def code
  @code
end

#detailObject

Returns the value of attribute detail.



8
9
10
# File 'lib/central_mail/upload_error.rb', line 8

def detail
  @detail
end

#upstream_http_resp_statusObject

Returns the value of attribute upstream_http_resp_status.



8
9
10
# File 'lib/central_mail/upload_error.rb', line 8

def upstream_http_resp_status
  @upstream_http_resp_status
end

Class Method Details

.default_message(code, pdf_validator_options = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/central_mail/upload_error.rb', line 29

def self.default_message(code, pdf_validator_options = {})
  begin
    message = UploadError.const_get(code.to_sym)
  rescue NameError
    message = DEFAULT_MESSAGE
  end

  opts = PDFUtilities::PDFValidator::Validator::DEFAULT_OPTIONS.merge(pdf_validator_options.to_h)

  case code.to_s
  when 'DOC106'
    "#{message} Limit is #{PDFUtilities.formatted_file_size(opts[:size_limit_in_bytes])} per document."
  when 'DOC108'
    "#{message} Limit is #{opts[:width_limit_in_inches]} in x #{opts[:height_limit_in_inches]} in."
  else
    message
  end
end