2016-09-13 9 views
2

はここAPI FINALLYLaravelのGuzzle Error。 RequestException.phpラインでClientException 107:

protected function processRequest($method, $sub_uri, $body = null, $headers = null) 
{ 
    $this->response = $this->guzzle_instance->request($method, $sub_uri, array(
     'headers' => $headers, 
     'body' => $body 
    )); 
} 

にログインしようとする試みをしようとする機能の私のコンストラクタここ

public function __construct() 
{ 
    $this->jar = new \GuzzleHttp\Cookie\CookieJar(); 
    $this->guzzle_instance = new \GuzzleHttp\Client([ 
     'base_uri' => API_URI, 
     'cookies' => $this->jar 
    ]); 
    return $this; 
} 

されている、ここで私をリダイレクトするチェックがありますログインに成功した場合や、何らかのメッセージをユーザーに返す場合

if ($authzor->attemptLogin($request['username'], $request['password'])) { 
     return redirect()->intended('dashboard'); 
    } else { 
     /** 
     * this is where i get the exception for login's that don't pass 
     */ 

     return "Username or password is missing." . $authzor->getResponse(); 
    } 

正しい資格情報を渡すと私はリダイレクトされますダッシュボードに、そうでない場合、私はRequestException.phpラインでのエラーClientExceptionを取得107:

なく、少なくとも最後に、ここで私はあなたの機能を変更してにあなたの要求を入れている

ClientException in RequestException.php line 107: 
Client error: `GET http://<host address>/api/v1/login/admin/testerson` 

resulted in a `403 Forbidden` response: 
{"timestamp":"2016-09-13T13:35:23-05:00","api_version":"v1","success":"false","message":"Invalid username\/password comb (truncated...) 
in RequestException.php line 107 
at RequestException::create(object(Request), object(Response)) in Middleware.php line 65 
at Middleware::GuzzleHttp\{closure}(object(Response)) in Promise.php line 203 
at Promise::callHandler('1', object(Response), array(object(Promise), object(Closure), null)) in Promise.php line 156 
at Promise::GuzzleHttp\Promise\{closure}() in TaskQueue.php line 61 
at TaskQueue->run(true) in Promise.php line 246 
at Promise->invokeWaitFn() in Promise.php line 223 
at Promise->waitIfPending() in Promise.php line 266 
at Promise->invokeWaitList() in Promise.php line 225 
at Promise->waitIfPending() in Promise.php line 62 
at Promise->wait() in Client.php line 129 
at Client->request('GET', 'login/admin/jdiscool', array('headers' => array('Content-Type' => 'application/json'), 'body' => null)) in ApiClient.php line 60 
at ApiClient->processRequest('GET', 'login/admin/jdiscool') in MOAuthenticator.php line 21 
at MOAuthenticator->attemptLogin('admin', 'jdiscool') in AuthController.php line 58 
at AuthController->authenticate(object(Request)) 
at call_user_func_array(array(object(AuthController), 'authenticate'), array(object(Request))) in Controller.php line 80 
at Controller->callAction('authenticate', array(object(Request))) in ControllerDispatcher.php line 146 
at ControllerDispatcher->call(object(AuthController), object(Route), 'authenticate') in ControllerDispatcher.php line 94 
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request)) 
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in RedirectIfAuthenticated.php line 24 
at RedirectIfAuthenticated->handle(object(Request), object(Closure)) 
at call_user_func_array(array(object(RedirectIfAuthenticated), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) 
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) 
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103 
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 96 
at ControllerDispatcher->callWithinStack(object(AuthController), object(Route), object(Request), 'authenticate') in ControllerDispatcher.php line 54 
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\Auth\AuthController', 'authenticate') in Route.php line 174 
at Route->runController(object(Request)) in Route.php line 140 
at Route->run(object(Request)) in Router.php line 724 
at Router->Illuminate\Routing\{closure}(object(Request)) 
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in VerifyCsrfToken.php line 64 
at VerifyCsrfToken->handle(object(Request), object(Closure)) 
at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) 
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ShareErrorsFromSession.php line 49 
at ShareErrorsFromSession->handle(object(Request), object(Closure)) 
at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) 
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in StartSession.php line 64 
at StartSession->handle(object(Request), object(Closure)) 
at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) 
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37 
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) 
at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) 
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in EncryptCookies.php line 59 
at EncryptCookies->handle(object(Request), object(Closure)) 
at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) 
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) 
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103 
at Pipeline->then(object(Closure)) in Router.php line 726 
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 699 
at Router->dispatchToRoute(object(Request)) in Router.php line 675 
at Router->dispatch(object(Request)) in Kernel.php line 246 
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) 
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44 
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) 
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) 
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) 
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103 
at Pipeline->then(object(Closure)) in Kernel.php line 132 
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99 
at Kernel->handle(object(Request)) in index.php line 51 

答えて

4

トレーススタックです200以外の応答を明示的に処理できるように試してください。

protected function processRequest($method, $sub_uri, $body = null, $headers = null) 
{ 
    try { 
     $this->response = $this->guzzle_instance->request($method, $sub_uri, array(
     'headers' => $headers, 
     'body' => $body 
     ));  
    } 
    catch (GuzzleHttp\Exception\ClientException $e) { 
     $response = $e->getResponse(); 
     $result = $response->getBody(); 

     //do something with it.... 

    } 
} 
関連する問題