Class: Users::ExceptionHandler

Inherits:
Object
  • Object
show all
Includes:
Common::Client::Concerns::ServiceStatus
Defined in:
app/services/users/exception_handler.rb

Constant Summary

Constants included from Common::Client::Concerns::ServiceStatus

Common::Client::Concerns::ServiceStatus::RESPONSE_STATUS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error, service) ⇒ ExceptionHandler

Returns a new instance of ExceptionHandler.

Parameters:

  • error (ErrorClass)

    An external service error

  • service (String)

    The name of the external service (i.e. ‘Vet360’, ‘MVI’, ‘EMIS’)



16
17
18
19
# File 'app/services/users/exception_handler.rb', line 16

def initialize(error, service)
  @error = validate!(error)
  @service = service
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



11
12
13
# File 'app/services/users/exception_handler.rb', line 11

def error
  @error
end

#serviceObject (readonly)

Returns the value of attribute service.



11
12
13
# File 'app/services/users/exception_handler.rb', line 11

def service
  @service
end

Instance Method Details

#serialize_errorHash

Serializes the initialized error into one of the predetermined error types. Uses error classes that can be triggered by MVI, EMIS, or Vet360.

The serialized error format is modelled after the Maintenance Windows schema, per the FE’s request.

window schema.

Returns:

  • (Hash)

    A serialized version of the initialized error. Follows maintenance

See Also:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/services/users/exception_handler.rb', line 31

def serialize_error
  case error
  when Common::Exceptions::BaseError
    base_error
  when VAProfile::VeteranStatus::VAProfileError
    if error.status == 404
      title_error(:not_found)
    else
      standard_va_profile_error
    end
  when Common::Client::Errors::ClientError
    client_error
  when MPI::Errors::RecordNotFound
    mpi_error(404)
  when MPI::Errors::FailedRequestError
    mpi_error(503)
  when MPI::Errors::DuplicateRecords
    mpi_error(404)
  else
    standard_error
  end
end