当提要输入错误时,为什么我在 Zend Feed 中没有得到预期的异常?

发布于 2024-07-29 21:00:58 字数 1113 浏览 7 评论 0原文

基本上,我们在这里提供了这个模块,供希望在其页面上的其他位置包含提要的用户使用。 我工作得很好,没有流汗。 问题是,每当用户错误处理手上的 feed 链接时,我们就必须手动删除该模块,因为 Zend Feed 会像任何致命错误一样崩溃并烧毁整个页面。 代码块,人们会期望诸如.. ..之类的代码块

try { // Test piece straight off the Zend tutorial
    $slashdotRss = Zend_Feed::import('http://rss.slashdot.org/Slashdot/slashdot');
} catch (Zend_Feed_Exception $e) {
    // feed import failed
    echo "Exception caught importing feed: {$e->getMessage()}\n";
    exit;
}

通常,如果我输入“httn://rss.grrllarrrllll.aarrg/Slashdot/slashdot”并说出“404”或“什么”之类的 会起作用。该死”。 不,它死了。 它崩溃并死亡。 它崩溃、燃烧、死亡,完全忽略了所有快乐的 trycatch 方法。

所以基本上,我们是否必须在 feedfetch 上编写我们的内容,或者是否有任何简单的补救措施来解决 Zend 的错误?

添加日志:

    exception 'Zend_Http_Client_Adapter_Exception' with message 'Unable to Connect to tcp://www.barglllrragglll:80. Error #10946: ' in /library/Zend/Http/Client/Adapter/Socket.php:148
#0 /library/Zend/Http/Client.php(827): Zend_Http_Client_Adapter_Socket->connect('www.barglllrragglll...', 80, false)
#1 /library/Zend/Feed.php(284): Zend_Http_Client->request()
...... Trace etc ....

Basically, we have this here module that we offer to our users that want to include a feed from elsewhere on their pages. I works great, no sweat. The problem is that whenever users mishandle the feed link on their hands we have to manually remove the module from existence because Zend Feed crashes and burns the entire page just like any fatal error. Normally, one would expect that a code block such as..

try { // Test piece straight off the Zend tutorial
    $slashdotRss = Zend_Feed::import('http://rss.slashdot.org/Slashdot/slashdot');
} catch (Zend_Feed_Exception $e) {
    // feed import failed
    echo "Exception caught importing feed: {$e->getMessage()}\n";
    exit;
}

.. would BEHAVE if I were to enter 'httn://rss.grrllarrrlll.aarrg/Slashdot/slashdot' and say something along the lines of "404" or "What the shit". No. It dies. It crashes and dies. It crashes and burns and dies, completely ignoring all that happy trycatch methology right there.

So basically, do we have to write our on feedfetch or is there any simple remedy to Zend's slip?

Added log:

    exception 'Zend_Http_Client_Adapter_Exception' with message 'Unable to Connect to tcp://www.barglllrragglll:80. Error #10946: ' in /library/Zend/Http/Client/Adapter/Socket.php:148
#0 /library/Zend/Http/Client.php(827): Zend_Http_Client_Adapter_Socket->connect('www.barglllrragglll...', 80, false)
#1 /library/Zend/Feed.php(284): Zend_Http_Client->request()
...... Trace etc ....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

时光沙漏 2024-08-05 21:01:01

嘿,你没有捕获正确的异常类型尝试捕获

Zend_Http_Client_Adapter_Exception

或同时出现:

捕获(异常$e)

顺便说一句,它有一个 toString 方法,因此您只需 echo $e 即可,无需 getMessages。

Hey, you are not catching the right exception type try to catch

Zend_Http_Client_Adapter_Exception

or all at once:

catch (Exception $e)

btw it has a toString method so you can just echo $e no need to getMessages.

逆蝶 2024-08-05 21:01:01

怎么样

$file = file("http://rss.grrrrrrrrl... ”);
$rss = Zend_Feed::importString($file);

?

How about something along the lines of

$file = file("http://rss.grrrrrrrl...");
$rss = Zend_Feed::importString($file);

?

披肩女神 2024-08-05 21:01:00

只是出于好奇,您是否尝试捕获其他类型的异常? 即,不仅仅是 Zend_Feed_Exception

也许,如果在“获取”阶段出现某种 404 错误,它会抛出另一个异常? (因为依赖另一个组件,比如 Zend_Http_Client ?)

另外,您是否检查了 error_reporting 级别,以确保会报告错误? 如果 display_errorsOff ,也许在某个日志文件中?

顺便说一句,这并不是您问题的真正答案,但是 Zend_Feed 有一些缺点(例如根据提要的格式返回不同类型的数据 - 例如 RSS 与 ATOM)< /em>.

从 Zend Framework 1.9 开始(目前,它仅作为预览版或 alpha 版本提供,因此不要在生产中使用它!),将会有一个 Zend_Feed_Reader 组件,这在使用 RSS 和 ATOM Feed 时应该更有用。

有关详细信息,请参阅


添加日志后编辑

对于Zend_Feed,Feed本身没有问题,因此不会抛出Zend_Feed代码>相关异常。

您这里遇到的问题是另一个问题,例如错误的 URL:它无法获取数据,并且无法分析它; 它解释了为什么异常与 Zend_Feed 无关,而是与 Zend_Http_Client 相关。

您可能想添加一些其他异常处理代码; 像这样:

try { // Test piece straight off the Zend tutorial
    $slashdotRss = Zend_Feed::import('http://rss.slashdot.org/Slashdot/slashdot');
} catch (Zend_Feed_Exception $e) {
    // feed import failed
    echo "Exception caught importing feed: {$e->getMessage()}\n";
    exit;
} catch (Zend_Http_Client_Exception $e) {
  echo "There is something wrong with the URL you provided for the feed";
  exit;
} catch (Exception $e) {
  echo "There is something wrong, we don't know what...";
  exit;
}

这样:

  • 如果提要无效,您可以告诉用户
  • 如果存在与HTTP相关的问题,您也可以告诉用户
  • 如果还有您没有想到的另一个问题,它仍然没有'崩溃

Just out of curiosity, did you try catching other kinds of exception ? ie, not only Zend_Feed_Exception ?

Maybe, if there is some kind of 404 error during the "fetching" phase, it throws another exception ? (Because of relying on another component, like Zend_Http_Client ? )

Also, did you check your error_reporting level, to be sure errors would be reported ? Maybe in some log file somewhere, if display_errors is Off ?

As a sidenot, and not really an answer to your question, but Zend_Feed has some drawbacks (like returning different kind of data depending on the feed's format -- RSS vs ATOM, for instance).

Starting with Zend Framework 1.9 (right now, it's only available as a preview or alpha version, so don't using it in production !), there will be a Zend_Feed_Reader component, which should be more useful when consumming both RSS and ATOM Feeds.

For more informations, see


Edit after you added the log

For Zend_Feed, there is no problem with the Feed itself, so it doesn't throw a Zend_Feed-related Exception.

The problem you have here is another one, like wrong URL : it fails getting the data, and not analysing it ; it explains why the exception is not Zend_Feed-related, but Zend_Http_Client-related.

You might want to add some other exception-handling-code ; something like this :

try { // Test piece straight off the Zend tutorial
    $slashdotRss = Zend_Feed::import('http://rss.slashdot.org/Slashdot/slashdot');
} catch (Zend_Feed_Exception $e) {
    // feed import failed
    echo "Exception caught importing feed: {$e->getMessage()}\n";
    exit;
} catch (Zend_Http_Client_Exception $e) {
  echo "There is something wrong with the URL you provided for the feed";
  exit;
} catch (Exception $e) {
  echo "There is something wrong, we don't know what...";
  exit;
}

This way :

  • If the feed is not valid, you can tell the user
  • If there is an HTTP-related problem, you can tell the user too
  • If there is another problem you didn't think about, it still doesn't crash
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文