Class: Users::ExceptionHandler
Constant Summary
Common::Client::Concerns::ServiceStatus::RESPONSE_STATUS
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of ExceptionHandler.
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
#error ⇒ Object
Returns the value of attribute error.
11
12
13
|
# File 'app/services/users/exception_handler.rb', line 11
def error
@error
end
|
#service ⇒ Object
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
#base_error ⇒ Object
62
63
64
65
66
67
68
69
|
# File 'app/services/users/exception_handler.rb', line 62
def base_error
exception = error.errors.first
error_template.merge(
description: "#{exception.code}, #{exception.status}, #{exception.title}, #{exception.detail}",
status: exception.status.to_i
)
end
|
#client_error ⇒ Object
71
72
73
74
75
76
|
# File 'app/services/users/exception_handler.rb', line 71
def client_error
error_template.merge(
description: "#{error.class}, #{error.status}, #{error.message}, #{error.body}",
status: error.status.to_i
)
end
|
92
93
94
95
96
97
|
# File 'app/services/users/exception_handler.rb', line 92
def client_error_related_to_title38
error_template.merge(
description: "#{error.class}, Client error related to title38",
status: 404
)
end
|
#error_template ⇒ Object
113
114
115
116
117
118
119
120
121
|
# File 'app/services/users/exception_handler.rb', line 113
def error_template
{
external_service: service,
start_time: Time.current.iso8601,
end_time: nil,
description: nil,
status: nil
}
end
|
#mpi_error(status) ⇒ Object
99
100
101
102
103
104
|
# File 'app/services/users/exception_handler.rb', line 99
def mpi_error(status)
error_template.merge(
description: "#{error.class}, #{error.message}",
status:
)
end
|
#serialize_error ⇒ Hash
Serializes the initialized error into one of the predetermined error types. Uses error classes that can be triggered by MVI or VA Profile (formerly Vet360).
The serialized error format is modelled after the Maintenance Windows schema, per the FE’s request.
window schema.
#standard_error ⇒ Object
106
107
108
109
110
111
|
# File 'app/services/users/exception_handler.rb', line 106
def standard_error
error_template.merge(
description: "#{error.class}, #{error.message}, #{error}",
status: standard_error_status(error)
)
end
|
#standard_error_status(error) ⇒ Object
123
124
125
126
127
128
|
# File 'app/services/users/exception_handler.rb', line 123
def standard_error_status(error)
error.try(:status).presence ||
error.try(:status_code).presence ||
error.try(:code).presence ||
503
end
|
#standard_va_profile_error ⇒ Object
85
86
87
88
89
90
|
# File 'app/services/users/exception_handler.rb', line 85
def standard_va_profile_error
error_template.merge(
description: "#{error.class}, #{error.message}, #{error} VA Profile failure",
status: standard_error_status(error)
)
end
|
#title_error(_type) ⇒ Object
78
79
80
81
82
83
|
# File 'app/services/users/exception_handler.rb', line 78
def title_error(_type)
error_template.merge(
description: "#{error.class}, 404 Veteran Status title not found",
status: 404
)
end
|
#validate!(error) ⇒ Object
56
57
58
59
60
|
# File 'app/services/users/exception_handler.rb', line 56
def validate!(error)
raise Common::Exceptions::ParameterMissing.new('error'), 'error' if error.blank?
error
end
|