2015-05-14 79 views
1

我通过其REST API连接到Docusign。目前,我正在拯救所有我认为不是好主意的例外情况。我想挽救API引发的某些异常。当我现在收到来自API的异常会显示在控制台以下:在Rails中挽救第三方REST API异常

{"errorCode"=>"USER_AUTHENTICATION_FAILED", "message"=>"One or both of Username and Password are invalid."} 

他们的错误的格​​式是:

(errorDetails.errorCode) and associated messages (errorDetails.message) 

我该如何拯救个别例外与他们是响应发回给我?我当前的代码是:

def show 

    begin 
    client = DocusignRest::Client.new 
    [Other API actions] 
    rescue [Rescue USER_AUTHENTICATION_FAILED here] 
    [log exception here] 
    rescue => e 
    [log exception here] 
    end 

end 

回答

0

您可以提供,你想救多个异常类:

begin 
    client = DocusignRest::Client.new 
    # do some stuff 
rescue DocusignCrazyError, DocusignBreakingError, DocusignAnotherError => error 
    # log exception 
end 
+0

但我怎么找出类的名字是什么。阅读他们的文档,这是我发现的一切:https://www.docusign.com/p/RESTAPIGuide/Content/Error%20Code/Error%20Codes%20and%20Associated%20Messages.htm我回来的唯一的事情是json响应。 – Questifer

+0

ErrorCode不在JSON响应中或者什么?不知道问题是什么。 – infused

+0

错误是在json响应中返回({“errorCode”=>“USER_AUTHENTICATION_FAILED”}),但我不确定在我的开始救援块中写入什么样的逻辑来拯救该错误?例如,我尝试了'救援DocusignUserAuthenticationFailed',它没有奏效。 – Questifer