# Exceptions in resources

**URL:** <https://discourse.chef.io/t/exceptions-in-resources/5799>\
**Category:** Chef Infra (archive)\
**Created:** [October 14, 2014, 6:34pm UTC](https://discourse.chef.io/t/exceptions-in-resources/5799 "2014-10-14T18:34:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_de\_la\_Garza](https://avatars.discourse-cdn.com/v4/letter/j/a698b9/32.png) [@John\_de\_la\_Garza](https://discourse.chef.io/u/John_de_la_Garza)\
**Post date:** [October 14, 2014, 6:34pm UTC](https://discourse.chef.io/t/exceptions-in-resources/5799/1 "2014-10-14T18:34:26Z")

</div>

I just asked a question about which exceptions to rescue when using  
http\_request. After  
doing some more research, I’ve learned that this question doesn’t really make  
sense…

I’ve read that I can’t catch the Exception at the time the recipe runs.

I have some code that uses Net::HTTP::Get that runs in a lwrp. I am  
able to rescue exceptions  
there. Must I write my own code to do an HTTP post if I need to have  
the run not  
fail just because it can’t post? The post is ideal, but optional…

---

<div class="post-metadata">

**Author:** ![Tensibai](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/tensibai/32/29_2.png) [@Tensibai](https://discourse.chef.io/u/Tensibai)\
**Post date:** [October 14, 2014, 6:42pm UTC](https://discourse.chef.io/t/exceptions-in-resources/5799/2 "2014-10-14T18:42:30Z")

</div>

Brief answer: no, you can use ignore\_failure in any resource to continue the chef run if it fails.

Side option the retry\_count (I think) attribute to let a resource retry its job in case of failure.

The doc about it is somewhere in the common options in [docs.getchef.Com](http://docs.getchef.Com), but on the phone I can't tell right now

---- John de la Garza a écrit ----

> I just asked a question about which exceptions to rescue when using  
> http\_request. After  
> doing some more research, I've learned that this question doesn't really make  
> sense...
> 
> I've read that I can't catch the Exception at the time the recipe runs.
> 
> I have some code that uses Net::HTTP::Get that runs in a lwrp. I am  
> able to rescue exceptions  
> there. Must I write my own code to do an HTTP post if I need to have  
> the run not  
> fail just because it can't post? The post is ideal, but optional...

---

<div class="post-metadata">

**Author:** ![coderanger](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/coderanger/32/5_2.png) [@coderanger](https://discourse.chef.io/u/coderanger)\
**Post date:** [October 14, 2014, 6:42pm UTC](https://discourse.chef.io/t/exceptions-in-resources/5799/3 "2014-10-14T18:42:42Z")

</div>

Can you back up and explain what you are trying to do?

--Noah

On Oct 14, 2014, at 11:34 AM, John de la Garza [john.garza@rallyhealth.com](mailto:john.garza@rallyhealth.com) wrote:

> I just asked a question about which exceptions to rescue when using  
> http\_request. After  
> doing some more research, I've learned that this question doesn't really make  
> sense...
> 
> I've read that I can't catch the Exception at the time the recipe runs.
> 
> I have some code that uses Net::HTTP::Get that runs in a lwrp. I am  
> able to rescue exceptions  
> there. Must I write my own code to do an HTTP post if I need to have  
> the run not  
> fail just because it can't post? The post is ideal, but optional...

---

<div class="post-metadata">

**Author:** ![John\_de\_la\_Garza](https://avatars.discourse-cdn.com/v4/letter/j/a698b9/32.png) [@John\_de\_la\_Garza](https://discourse.chef.io/u/John_de_la_Garza)\
**Post date:** [October 14, 2014, 7:31pm UTC](https://discourse.chef.io/t/exceptions-in-resources/5799/4 "2014-10-14T19:31:10Z")

</div>

On Tue, Oct 14, 2014 at 2:42 PM, Noah Kantrowitz [noah@coderanger.net](mailto:noah@coderanger.net) wrote:

> Can you back up and explain what you are trying to do?
> 
> --Noah

I have a recipe that does a http\_request to post to a REST api. If  
that api is down I don't want  
the entire run to fail, I just want a log entry and for the run continue.

---

<div class="post-metadata">

**Author:** ![kallistec](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/kallistec/32/23_2.png) [@kallistec](https://discourse.chef.io/u/kallistec)\
**Post date:** [October 15, 2014, 3:01pm UTC](https://discourse.chef.io/t/exceptions-in-resources/5799/5 "2014-10-15T15:01:52Z")

</div>

On Tuesday, October 14, 2014 at 8:31 PM, John de la Garza wrote:

> On Tue, Oct 14, 2014 at 2:42 PM, Noah Kantrowitz \<[noah@coderanger.net](mailto:noah@coderanger.net) ([mailto:noah@coderanger.net](mailto:noah@coderanger.net))\> wrote:
> 
> > Can you back up and explain what you are trying to do?
> > 
> > --Noah
> 
> I have a recipe that does a http\_request to post to a REST api. If  
> that api is down I don't want  
> the entire run to fail, I just want a log entry and for the run continue.

Look at `ignore_failure` here: [Common Resource Functionality](http://docs.getchef.com/resource_common.html)

--  
Daniel DeLeo
