TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Unified HTTP exception handling for Ruby

33 pointsby fredsters_salmost 11 years ago

2 comments

djuralmost 11 years ago
Handy! A lot of Ruby libraries do a pretty bad job protecting their users from underlying exceptions that should be handled within the library. I&#x27;m hoping that with exception causes in Ruby 2.1, we&#x27;ll see more libraries wrapping common exceptions.<p>Another option for dealing with sloppy exception handling by libraries is toe_tag, which we open-sourced at my work:<p><a href="https://github.com/crowdcompass/toe_tag" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;crowdcompass&#x2F;toe_tag</a><p>It allows you to declare groups of exceptions that can be caught with a single rescue clause. This has been extremely useful when dealing with ActiveRecord&#x27;s tendency to bubble up exceptions from the underlying drivers -- the native and JDBC drivers for Postgres raise completely different exceptions for the same errors.<p>In some cases, exception classes aren&#x27;t enough to determine whether an exception actually should be caught. A lot of libraries end up forcing you to make decisions based on the text of the message, or on some custom method (#error_code or what have you). toe_tag helps clean up those checks too.
评论 #8194759 未加载
评论 #8193905 未加载
评论 #8194023 未加载
smathieualmost 11 years ago
Original gem author here!<p>We were scratching out own itch by doing this. This is currently used by several of our projects.<p>It does feel like the HTTP libraries should be better and handling these various exceptions. Since they don&#x27;t, we&#x27;ve ended up writing this.<p>For the most part, whenever we do any HTTP call, we are expecting a specific return code and we want to raise an easy to handle exception when this happens. However, many HTTP call don&#x27;t even get to the point where an error code is return when the network is not reliable. We&#x27;ve found that in most case, we want to handle that exception in the same way than an unexpected error code.<p>This little gem let us do that easily.<p>Enjoy :)