# Handling API exception in action server with a user-friendly bot utterance

**URL:** <https://forum.rasa.com/t/handling-api-exception-in-action-server-with-a-user-friendly-bot-utterance/49794>\
**Category:** Rasa Open Source\
**Created:** [December 7, 2021, 4:54am UTC](https://forum.rasa.com/t/handling-api-exception-in-action-server-with-a-user-friendly-bot-utterance/49794 "2021-12-07T04:54:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![srikanthnm](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/srikanthnm/32/19387_2.png) [@srikanthnm](https://forum.rasa.com/u/srikanthnm)\
**Post date:** [December 7, 2021, 4:54am UTC](https://forum.rasa.com/t/handling-api-exception-in-action-server-with-a-user-friendly-bot-utterance/49794/1 "2021-12-07T04:54:39Z")

</div>

Hi, I call an external API from within the Rasa actions server (Rasa open source 2.8.8). Specifically, I use a try-catch block and use a dispatch.utter\_message in the except block to have the bot display a user-friendly message when there is an exception like a connection issue. But, the bot prints nothing from within the action server whenever an exception is encountered. Any pointers would be of great help.

---

<div class="post-metadata">

**Author:** ![ChrisRahme](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/chrisrahme/32/15572_2.png) [@ChrisRahme](https://forum.rasa.com/u/ChrisRahme)\
**Post date:** [December 7, 2021, 6:20am UTC](https://forum.rasa.com/t/handling-api-exception-in-action-server-with-a-user-friendly-bot-utterance/49794/2 "2021-12-07T06:20:43Z")

</div>

Weird.

What’s your front-end? Rasa Shell, Rasa X, or something else? Rasa X sometimes fails to display the message on actions that make database queries and API calls.

You can use `print()` inside the action and it will get printed in the action server’s logs.

---

<div class="post-metadata">

**Author:** ![srikanthnm](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/srikanthnm/32/19387_2.png) [@srikanthnm](https://forum.rasa.com/u/srikanthnm)\
**Post date:** [December 7, 2021, 9:31am UTC](https://forum.rasa.com/t/handling-api-exception-in-action-server-with-a-user-friendly-bot-utterance/49794/3 "2021-12-07T09:31:29Z")

</div>

Hi - thanks for your response.   
My front-end is Rasa Webchat JavaScript.   
For the successful API requests, I am able to print the responses. It is when the API server is down when I am unable to send a meaningful response to the user.

---

<div class="post-metadata">

**Author:** ![ChrisRahme](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/chrisrahme/32/15572_2.png) [@ChrisRahme](https://forum.rasa.com/u/ChrisRahme)\
**Post date:** [December 7, 2021, 11:01am UTC](https://forum.rasa.com/t/handling-api-exception-in-action-server-with-a-user-friendly-bot-utterance/49794/4 "2021-12-07T11:01:51Z")

</div>

Did you put a `print()` in the `except` block to make sure it’s getting there?

---

<div class="post-metadata">

**Author:** ![srikanthnm](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/srikanthnm/32/19387_2.png) [@srikanthnm](https://forum.rasa.com/u/srikanthnm)\
**Post date:** [December 8, 2021, 11:53am UTC](https://forum.rasa.com/t/handling-api-exception-in-action-server-with-a-user-friendly-bot-utterance/49794/5 "2021-12-08T11:53:32Z")

</div>

Thanks for your suggestion. It indeed wasn’t getting to the except block. There was some issue with my code changes not reflecting in the action server. Clearing the pycache folder helped and now, it works as expected. Thanks again

---

<div class="post-metadata">

**Author:** ![ishant6531](https://avatars.discourse-cdn.com/v4/letter/i/a88e4f/32.png) [@ishant6531](https://forum.rasa.com/u/ishant6531)\
**Post date:** [July 11, 2022, 2:46pm UTC](https://forum.rasa.com/t/handling-api-exception-in-action-server-with-a-user-friendly-bot-utterance/49794/6 "2022-07-11T14:46:22Z")

</div>

Thanks for the solution , i was facing same problem except block was not working in actions.py file , after clearing pycache folder now it is working fine. thanks a lot for the solution
