2016-10-04 39 views
-1

使用ActionCable後,如何從客戶端接收數據後發生錯誤?ActionCable - 迴應錯誤

例如,當客戶端未通過身份驗證時,ActionCable會拋出UnauthorizedError,並以404作爲響應。例如,當客戶端發送的數據無效時,我想用422響應。

+0

的可能重複http://stackoverflow.com/q/39650446/5381547 – Viktor

回答

0
ActionCable.server.broadcast "your_channel", message: {data: data, code: 422} 

然後在your.coffee文件:

received: (res) -> 
    switch res.code 
    when 200 
     # your success code 
     # use res.data to access your data message 
    when 422 
     # your error handler