使用Twilio API进行堆栈级别太深错误

时间:2018-02-02 20:58:08

标签: ruby-on-rails ruby-on-rails-4 stack twilio

所以我试图将Twilio Programmable Video API与我的Rails应用程序集成,然后我为它创建了一个单独的控制器:

require 'twilio-ruby'

class Api::V1::Coach::TwilioController < Api::V1::BaseController
  ACCOUNT_SID = ENV.fetch('TWILIO_ACCOUNT_SID')
  TWILIO_API_SID = ENV.fetch('TWILIO_KEY_SID')
  TWILIO_SECRET_KEY = ENV.fetch('TWILIO_SECRET_KEY')

  before_action :connect_to_twilio

  def create_room
    room = @twilio_token.video.rooms.create(
      unique_name: '12345',
      type: 'peer-to-peer',
      enable_turn: false
    ) 
    return render status:200, json: {     # This is the line indicated in the error
      success:true,
      jwt_token: @client,
      room_id: room.sid,
      room_status: room.status,
      room: room
    }
  end

   def connect_to_twilio
     @twilio_token = Twilio::REST::Client.new(TWILIO_API_SID, TWILIO_SECRET_KEY)
   end
end

但每次我向方法发出请求时都会收到错误:

SystemStackError (stack level too deep)

这看起来很奇怪,因为这里没有递归调用。

我认为错误是因为API请求。但是,如果我再次发出相同的请求,则会引发room already exists的不同错误。所以API请求是成功的,也许渲染有问题但是我不能真正指责它:/

0 个答案:

没有答案