Class: Preneeds::Middleware::Response::EoasXmlErrors
- Inherits:
-
Faraday::Response::Middleware
- Object
- Faraday::Response::Middleware
- Preneeds::Middleware::Response::EoasXmlErrors
- Includes:
- SentryLogging
- Defined in:
- lib/preneeds/middleware/response/eoas_xml_errors.rb
Overview
Faraday response middleware that checks the EOAS service response for errors and raises the appropirate exception for our application.
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#detail ⇒ Object
readonly
Returns the value of attribute detail.
-
#fault ⇒ Object
readonly
Returns the value of attribute fault.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#on_complete(env) ⇒ Faraday::Env
Checks the response for service errors and raises an exception if appropriate.
Methods included from SentryLogging
#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
11 12 13 |
# File 'lib/preneeds/middleware/response/eoas_xml_errors.rb', line 11 def code @code end |
#detail ⇒ Object (readonly)
Returns the value of attribute detail.
11 12 13 |
# File 'lib/preneeds/middleware/response/eoas_xml_errors.rb', line 11 def detail @detail end |
#fault ⇒ Object (readonly)
Returns the value of attribute fault.
11 12 13 |
# File 'lib/preneeds/middleware/response/eoas_xml_errors.rb', line 11 def fault @fault end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
11 12 13 |
# File 'lib/preneeds/middleware/response/eoas_xml_errors.rb', line 11 def status @status end |
Instance Method Details
#on_complete(env) ⇒ Faraday::Env
Checks the response for service errors and raises an exception if appropriate
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/preneeds/middleware/response/eoas_xml_errors.rb', line 17 def on_complete(env) return unless env.response_headers['content-type']&.match?(/\b(xml)/) @fault = fault_string(env) @code = return_code(env) return unless backend_error?(env) || status_200_error?(env) @status = status_200_error?(env) ? return_code(env) : env.status @detail = fault || return_description(env) # strip percentages from xml because Sentry uses it for interpolation extra_context = { original_status: status, original_body: env.body&.delete('%') } ('Generalized XML error response from EOAS', :warn, extra_context) raise Common::Exceptions::BackendServiceException.new('VA900', response_values, @status, env.body) end |