-
Notifications
You must be signed in to change notification settings - Fork 94
API 55333 POA slack alerts #27776
API 55333 POA slack alerts #27776
Changes from 3 commits
158d641
55c1284
69330ae
4fa56a8
34ddfc8
e523994
5fe4c3e
a895e73
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ | |
| module ClaimsApi | ||
| module V2 | ||
| module Veterans | ||
| class PowerOfAttorney::RequestController < ClaimsApi::V2::Veterans::PowerOfAttorney::BaseController | ||
| class PowerOfAttorney::RequestController < ClaimsApi::V2::Veterans::PowerOfAttorney::BaseController # rubocop:disable Metrics/ClassLength | ||
| FORM_NUMBER = 'POA_REQUEST' | ||
| MAX_PAGE_SIZE = 100 | ||
| MAX_PAGE_NUMBER = 100 | ||
|
|
@@ -194,7 +194,7 @@ def get_dependent_name(icn) | |
| end | ||
|
|
||
| # rubocop:disable Metrics/ParameterLists | ||
| def process_poa_decision(decision:, proc_id:, representative_id:, poa_code:, metadata:, veteran:, claimant:) | ||
| def process_poa_decision(decision:, proc_id:, representative_id:, poa_code:, metadata:, veteran:, claimant:) # rubocop:disable Metrics/MethodLength | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you refactor this method so it's more object oriented and less procedural? Just based on the comments, there could be a method to build headers, and a method to save the record. (the main ask here is to avoid disabling rubocop.)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Making ticket to refactor this further to remove the |
||
| result = ClaimsApi::PowerOfAttorneyRequestService::DecisionHandler.new( | ||
| decision:, proc_id:, registration_number: representative_id, poa_code:, metadata:, veteran:, claimant: | ||
| ).call | ||
|
|
@@ -217,8 +217,12 @@ def process_poa_decision(decision:, proc_id:, representative_id:, poa_code:, met | |
| power_of_attorney # return to the decide method for the response | ||
| rescue => e | ||
| claims_v2_logging('process_poa_decision', | ||
| level: :error, | ||
| message: "Failed to save power of attorney record. Error: #{e}") | ||
| raise e | ||
| poa_request_slack_alert('POA Decide Request', | ||
| "Failed to process POA decision for id: #{params[:id]}, " \ | ||
| "procId: #{proc_id} in #{Rails.env}: #{e.message}") | ||
| raise | ||
| end | ||
| # rubocop:enable Metrics/ParameterLists | ||
|
|
||
|
|
@@ -242,7 +246,12 @@ def validate_mapped_data!(veteran_participant_id, type, poa_code) | |
|
|
||
| def log_and_raise_decision_error_message! | ||
| claims_v2_logging('process_poa_decision', | ||
| message: 'Encountered issues validating the mapped data') | ||
| level: :error, | ||
| message: "Encountered issues validating the mapped data for POA id: #{params[:id]}: " \ | ||
| "#{@claims_api_forms_validation_errors}") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not actually gettin the text in the error log I was hoping for. I think we need an update to the Something along these lines (pseudo code here just FYI) I'm not a huge fan of passing in the instance variable for the errors, seems odd but I think we need to send in the errors since it would be one or the other. This would look like this which I think helps us understand the error more, otherwise we know it is a 422, but have no idea why.
|
||
| poa_request_slack_alert('POA Decide Request', | ||
| "Validation errors in mapped data for POA id: #{params[:id]} in #{Rails.env}: " \ | ||
| "#{@claims_api_forms_validation_errors}") | ||
|
|
||
| raise ::Common::Exceptions::UnprocessableEntity.new( | ||
| detail: 'An error occurred while processing this decision. Please try again later.' | ||
|
|
@@ -486,6 +495,20 @@ def page_number_to_index(number) | |
| number - 1 | ||
| end | ||
|
|
||
| def poa_request_slack_alert(source, message) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @siddharthalamsal This slack alert method could potentially be something we want to utilize elsewhere in the app at some point. Wondering what you thoughts would be on making this a module that we can include in this controller? Something like ClaimsApi::SlackNotifier etc. . We could rename the method as Thinking of a utilization along the lines of the claims_vs_logging . But it could just be included at that top level (application_controller) as a module, or just the method there just like the logging, that may also be enough given it is just the one method. I realize it is a bit of a refactor to the work here. But worth it to perhaps get in place from the start instead of hoping the refactor comes in the future. Let me know you think of the idea.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great idea, I like the module plan, on it! |
||
| webhook_url = Settings.claims_api.slack.webhook_url.to_s | ||
| return if webhook_url.blank? | ||
|
|
||
| slack_client = SlackNotify::Client.new(webhook_url:, | ||
| channel: '#api-benefits-claims-alerts', | ||
| username: "Failed #{source}") | ||
| slack_client.notify(message) | ||
| rescue => e | ||
| ClaimsApi::Logger.log('poa_request_slack_alert', | ||
| level: :error, | ||
| message: "Failed to send Slack alert: #{e.message}") | ||
| end | ||
|
|
||
| def normalize(item) | ||
| item.to_s.strip.downcase | ||
| end | ||
|
|
||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to discourage disabling the rubocop here and instead keeping the class smaller. Refactoring this might fit in with Rockwell's suggestion.