magento api soapclient 的显示错误

display error of magento api soapclient

我正在使用 laravel 4 框架和 magento api soap。这是我的登录方法:

    public function APIauthentication( $apiUser, $apiKey ) {

        $error = array();

        if( empty( $apiUser ) ) {
                $error[] = 'Unknown api user';
        }

        if( empty( $apiKey ) ) {
                $error[] = 'Invalid api key';
        }

        if( empty( $error ) ) {

                $client = $this->_getClient();
                $token = $client->login( $apiUser, $apiKey );
                $this->_setToken( $token );

                return $this->_apiJsonResult( $token );
        } else {
                return $this->_apiJsonResult( $error );
        }

}

我正在进入 laravel 屏幕 SoapFault 访问被拒绝。

如果 url 不正确或 API user/key 不正确,我需要 return 错误字符串。

像这样:

return Redirect::to('user/stores/magento/')->with('status', 'apie user or key is incorrect');

如何做到这一点?有故障代码,但我不知道如何记录 http://www.magentocommerce.com/api/soap/introduction.html#Introduction-GlobalAPIFaults

SoapFault 是需要捕获的异常。可以通过异常访问故障代码和错误字符串。另外,确保 SoapClient 是在 'exceptions' 选项设置为 true 的情况下实例化的,否则我相信 PHP 只会抛出一个致命错误。

if( empty( $error ) ) {
    $client = $this->_getClient();
    try {
        $token = $client->login( $apiUser, $apiKey );
    } catch (SoapFault $e) {
        // login failed logic
        $faultcode = $e->faultcode; // ex: 2
        $message = $e->faultstring; // ex: Access denied.
        // return redirect, etc...
    }
    // login successful logic
    $this->_setToken( $token );

    return $this->_apiJsonResult( $token );
} else {
    return $this->_apiJsonResult( $error );
}