Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
306 views
in Technique[技术] by (71.8m points)

ruby - API Requests not being sent in Production w/Excon Rails 6.0.0

I'm having an issue where my POST request with Excon gem is not being sent out in production, but works perfectly in development. In my logs, it shows Processing ServiceFormsControlller#run_background_check as HTML. I don't know exactly why this is happening...It was working perfectly last week. Now all of a sudden, no requests are being sent out from the production server...It shows the action taking place, but the API endpoint never receives the POST. I added the website to my CORS configuration as a whitelisted domain. That didn't do anything to improve the results.

service_forms_controller.rb

class ServiceFormsController < ApplicationController
 @service_form = ServiceForm.find(params[:id])
 @service_info = @service_form.info

 if @service_info.first_name.present? && @service_info.last_name.present? && @service_info.ssn.present? && @service_info.address.present? && @service_info.email.present?

@report_builder = GoodHire.new
if Rails.env.production?
 @report_builder.create_report_for_candidate(@service_info.first_name, @service_info.last_name, @service_info.ssn, @service_info.address, @service_info.email)
# other mandatory fields added to this call
end
  redirect_to service_forms_path, notice: "You've submitted the candidate for a background check"
  else
redirect_to service_forms_path, notice: "The candidate doesn't have all fields completed"
end

good_hire.rb

class GoodHire
  API_KEY_PROD = 'ZZzazzee'

include RestClient
include Excon

def create_report_for_candidate(first_name, last_name, email, ssn, address, city, state, zip, work_histories =[].....,api_key = API_KEY_PROD)

begin
 Excon.post("https://api.goodhire.com/v1/Report", body: {
  "Candidate": {
  "FirstName": "#{first_name}"
  ....
  ...  
},
"Offer": {
  "Products": [
  "....ID"  
 ]
},
 "RequestOptions": {
  "SendPurchaseReceipt": true 
  }
}.to_json, headers: {"Content-Type" => "application/json", "Authorization" => "ApiKey #{api_key}"})
 rescue Excon::Errors => e
 puts "RESPONSE ERROR #{e.response}"
  end
end

Server Development Log

Started POST "/service_forms/7/run_candidate_bckground_check?id=7" for 127.0.0.1
Processing by ServiceFormsController#run_candidate_background_check as HTML
Parameters: {"authenticity_token" => "zregegegergergergegegege", "id" => "7", "service_form_id"=> "7"}

app/controllers/service_forms_controller.rb: in `run_candidate_background_check'
Redirected to https://127.0.0.1:3000/service_forms 
Completed 302 Found in 4359ms

Started GET "/service_forms" for 127.0.0.1

initate_background_check.html.erb

<body>
 <%= button_to service_form_run_candidate_background_check(service_form_id: @service_form.id, id: @service_form.id), method: :post, class: 'bttn-simple bttn-sm bttn-primary'do %>
  Start Background Check
<% end %>
</body>
question from:https://stackoverflow.com/questions/65888792/api-requests-not-being-sent-in-production-w-excon-rails-6-0-0

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

API Validations caused API requests to fail


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...