如何处理"请求被Throttle服务器拒绝" Laravel 5

时间:2015-05-27 15:14:58

标签: php web-services soap laravel-5 throttling

我创建了一个使用SOAP交换从Web API获取数据的Web应用程序。这最初是以程序方式完成的,我现在正试图将其转移到Laravel框架中。我有一个view设置,如果SOAP响应是"请求被Throttle服务器拒绝,则显示给用户"但我不知道如何检查该特定错误。这是班级:

<?php namespace App\Models;

use SoapClient;
use Illuminate\Http\RedirectResponse;

class SoapWrapper {

public function soapExchange() {

    // set WSDL for authentication and create new SOAP client
    $auth_url  = "http://search.webofknowledge.com/esti/wokmws/ws/WOKMWSAuthenticate?wsdl";

    // set WSDL for search and create new SOAP client
    $search_url = "http://search.webofknowledge.com/esti/wokmws/ws/WokSearch?wsdl";

    // array options are temporary and used to track request & response data
    $auth_client = @new SoapClient($auth_url);

    // array options are temporary and used to track request & response data
    $search_client = @new SoapClient($search_url);

    // run 'authenticate' method and store as variable
    $auth_response = $auth_client->authenticate();

    // call 'setCookie' method on '$search_client' storing SID (Session ID) as the response (value) given from the 'authenticate' method
    // check if an SID has been set, if not it means Throttle server has stopped the query, therefore display error message
    if (isset($auth_response->return)) {
        $search_client->__setCookie('SID',$auth_response->return);
    } else {
        return Redirect::route('throttle');
    }
}
}

问题在于它会抛出由Throttle服务器拒绝的请求&#34; $auth_response = $auth_client->authenticate();之前的默认Laravel错误,它到达if语句,检查SOAP请求是否返回了值(SessionID)。当它出于某种原因以程序方式设置时,它没有做到这一点。

if语句检查是否已从authenticate()方法返回一个值,如果有,则将其(SessionID)分配给搜索客户端的cookie以授权搜索。否则会显示自定义错误消息。

我尝试过使用is_soap_fault,但这并没有抓住它,因为它在技术上并不是肥皂故障。我还尝试删除导致问题的行并将if语句更改为:

if (isset($auth_client->authenticate()->return) {...

但这只会导致默认的Laravel SoapFault页面。 return Redirect::route('throttle')向用户显示自定义错误页面,保存为throttle.blade.php

任何人都知道我如何测试油门错误?

1 个答案:

答案 0 :(得分:0)

没关系,在这里找到答案:Catching an exception when creating a new SoapClient properly

我会发布修改后的代码,以防万一以后对其他人有用:

<?php namespace App\Models;

use SoapClient;
use Illuminate\Http\RedirectResponse;

class SoapWrapper {

public function soapExchange() {

    try {
        // set WSDL for authentication and create new SOAP client
        $auth_url = "http://search.webofknowledge.com/esti/wokmws/ws/WOKMWSAuthenticate?wsdl";

        // set WSDL for search and create new SOAP client
        $search_url = "http://search.webofknowledge.com/esti/wokmws/ws/WokSearch?wsdl";

        // array options are temporary and used to track request & response data
        $auth_client = @new SoapClient($auth_url);

        // array options are temporary and used to track request & response data
        $search_client = @new SoapClient($search_url);

        // run 'authenticate' method and store as variable
        $auth_response = $auth_client->authenticate();

        // add SID (SessionID) returned from authenticate() to cookie of search client
        $search_client->__setCookie('SID', $auth_response->return);

    } catch (\SoapFault $e) {
        return Redirect::route('throttle');
    }
}
}