Я создал конечную точку webhook для стороннего API, но проблема, с которой я столкнулся, заключается в том, что webhook не удается обработать некоторые атрибуты, использующие массивы. Я не могу понять, почему он не корректно обновляет / сохраняет изменения, которые webhook вносит в систему. Как я могу исправить свою конечную точку webhook, чтобы позволить вносить изменения?
Ошибка
Started POST "/gh_webhook" for ..... at 2020-04-06 10:58:02 -0400
Cannot render console from ....! Allowed networks: ..., ::1
Processing by GHController#gh_webhook as HTML
Parameters: {"Id"=>"459b58d7-5a9e", "ReportStatus"=>{"Id"=>"7eac420d", "Status"=>"New", "StatusDetails"=>"New", "CheckStatuses"=>[]}, "good_hire"=>{"Id"=>"459b58d7-5a9e", "ReportStatus"=>{"Id"=>"7eac420d", "Status"=>"New", "StatusDetails"=>"New", "CheckStatuses"=>[]}}}
Completed 500 Internal Server Error in 3ms (ActiveRecord: 0.0ms | Allocations: 1164)
NoMethodError (undefined method `[]' for nil:NilClass):
app/controllers/gh_controller.rb:7:in `gh_webhook'
GH контроллер webhook
class GHController < ApplicationController
skip_before_action :verify_authenticity_token
def gh_webhook
resp = JSON.parse(request.body.read)
report_id = resp["Id"]
candidate_first_name = resp["ReportStatus"]["Candidate"]["FirstName"]
candidate_last_name = resp["ReportStatus"]["Candidate"]["LastName"]
candidate_middle_name = resp["ReportStatus"]["Candidate"]["MiddleName"]
candidate_email = resp["ReportStatus"]["Candidate"]["Email"]
report_status = resp["ReportStatus"]["Status"]
report_status_details = resp["ReportStatus"]["Pending"]
report_adverse_action_status = resp["ReportStatus"]["AdverseActionStatus"]
report_viewer_url = resp["ReportStatus"]["ReportViewerUrl"]
candidate_url = resp["ReportStatus"]["CandidateUrl"]
required_report_actions = resp["ReportStatus"]["RequiredReportActions"]
check_statuses = resp["ReportStatus"]["CheckStatuses"]
sections_containing_alerts = resp["ReportStatus"]["SectionsContainingAlerts"]
background_check_report = BackgroundCheckReport.find_by_report_id(report_id) || BackgroundCheckReport.create(report_id: report_id)
background_check_report.update(candidate_first_name: candidate_first_name, candidate_last_name: candidate_last_name, candidate_middle_name: candidate_middle_name, candidate_email: candidate_email, report_status: report_status, report_viewer_url: report_viewer_url, candidate_url: candidate_url, report_status_details: report_status_details, sections_containing_alerts: sections_containing_alerts, check_statuses: check_statuses, required_report_actions: required_report_actions, adverse_action_status: report_adverse_action_status)
head :ok
end
end
схема
create_table "background_check_reports", force: :cascade do |t|
t.string "candidate_first_name"
t.string "candidate_last_name"
t.string "candidate_email"
t.string "report_status"
t.string "report_status_details"
t.string "report_viewer_url"
t.string "candidate_url"
t.bigint "provider_form_id"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.string "report_id"
t.string "candidate_middle_name"
t.json "sections_containing_alerts"
t.json "required_report_actions"
t.json "check_statuses"
t.string "adverse_action_status"
end