Пример #1
0
{
    static function throwException($code, $data = null)
    {
        $message = ErrorMessages::getMessage($code);
        $rcpCode = ErrorMessages::getRpcCode($code);
        $httpStatus = ErrorMessages::getHttpStatus($code);
        throw (new ApplicationException($message, $code))->setData($data)->setHttpStatus($httpStatus)->setRpcErrorCode($rcpCode);
    }
}
function doSomething()
{
    RequestFailed::throwException(ErrorMessages::SESSION_ERROR_SESSION_NOT_VALID_CODE, ['this is the data', 'something' => 'else']);
    //	UserError::invalidData();
}
try {
    doSomething();
    // throw new FrameworkException(JSONRPC_ERROR_METHOD_NOT_FOUND, JSONRPC_ERROR_METHOD_NOT_FOUND_CODE);
    // throw new RequestFailedException( ERROR_SESSION_NOT_VALID, ERROR_SESSION_NOT_VALID_CODE );
} catch (\Exception $exception) {
    print " catch : " . get_class($exception) . "\n";
    $errorResponse = \ErrorResponse::fromException($exception);
    var_dump($errorResponse);
    print_r($errorResponse->getData()['trace']);
    return;
    print "Exception caught: \n";
    print "\t" . get_class($exception) . "\n";
    print "\t\t http Status : " . $exception->getHttpStatus() . "\n";
    print "\t\t message : " . $exception->getMessage() . "\n";
    print "\t\t error code : " . $exception->getCode() . "\n";
    print "\t\t data : " . print_r($exception->getData(), true) . "\n";
}
Пример #2
0
 function handle($request)
 {
     $this->request = $request;
     //
     // Set up to catch responses that drop outof the sky
     //
     ErrorHandler::setRequest($request);
     ErrorHandler::handleFatalErrors(function ($response) {
         $this->onErrorResponseFromHandlers($response);
     });
     ErrorHandler::handleScriptErrors(function ($response) {
         $this->onErrorResponseFromHandlers($response);
     });
     //		ErrorHandler::handleExceptions(function($response){ $this->onErrorResponseFromHandlers($response); });
     try {
         $this->doSetUp();
         try {
             $this->doSomething();
             $returnedValues = "good response";
             $response = new GoodResponse($this->request, $returnedVlaues);
             //
             // Here make the doSomething response into a FULL response
             //
         } catch (Exception $exception) {
             $response = ErrorResponse::fromException($exception);
             var_dump($response);
         }
     } catch (\Exception $exception) {
         $response = "outter catch block";
         //sendResponse($response);
     }
     $this->sendResponse($response);
 }