protected function processRequest(array $request)
    {
        try {
            $response = $this->_request(
                [
                    'uri' => $request['uri'],
                    'type' => $request['type'],
                    'data' => $request['data']
                ]
            );
        } catch ( \Exception $e ) {
            echo json_encode(array(
                'error' => array(
                    'msg' => $e->getMessage(),
                    'code' => $e->getCode(),
                ),
            ));

            exit();
        }

        return $response->getBody()->getContents();
    }
protected function processRequest(array $request)
    {
        try {
            $response = $this->_request(
                [
                    'uri' => $request['uri'],
                    'type' => $request['type'],
                    'data' => $request['data']
                ]
            );
        } catch ( \Exception $e ) {
            echo json_encode(array(
                'error' => array(
                    'msg' => $e->getMessage(),
                    'code' => $e->getCode(),
                ),
            ));

            exit();
        }

        return $response->getBody()->getContents();
    }
protected function processRequest ( array $ request ) { try { $ response = $ this -> _request ( [ 'uri' => $ request [ 'uri' ] , 'type' => $ request [ 'type' ] , 'data' => $ request [ 'data' ] ] ) ; } catch ( \ Exception $ e ) { echo json_encode ( array ( 'error' => array ( 'msg' => $ e -> getMessage ( ) , 'code' => $ e -> getCode ( ) , ) , ) ) ; exit ( ) ; } return $ response -> getBody ( ) -> getContents ( ) ; }
Process requests, catch exceptions, return json response

@param array $request uri, type, data from method
@return string json encoded response
Process requests catch exceptions return json response