Skip to content

Commit 3622b68

Browse files
authored
Fix #206 Add error handling to view submission code snippet in docs (#359)
1 parent bdba69a commit 3622b68

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

docs/_basic/ja_listening_modals.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ order: 12
2020
```python
2121
# view_submission イベントを処理
2222
@app.view("view_1")
23-
def handle_submission(ack, body, client, view):
23+
def handle_submission(ack, body, client, view, logger):
2424
# `block_c`という block_id に `dreamy_input` を持つ input ブロックがある場合
2525
hopes_and_dreams = view["state"]["values"]["block_c"]["dreamy_input"]
2626
user = body["user"]["id"]
@@ -44,8 +44,12 @@ def handle_submission(ack, body, client, view):
4444
except Exception as e:
4545
# エラーをハンドリング
4646
msg = "There was an error with your submission"
47-
finally:
48-
# ユーザーにメッセージを送信
47+
48+
# ユーザーにメッセージを送信
49+
try:
4950
client.chat_postMessage(channel=user, text=msg)
51+
except e:
52+
logger.exception(f"Failed to post a message {e}")
53+
5054
```
5155
</div>

docs/_basic/listening_modals.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Read more about view submissions in our <a href="https://api.slack.com/surfaces/
2020
```python
2121
# Handle a view_submission event
2222
@app.view("view_1")
23-
def handle_submission(ack, body, client, view):
23+
def handle_submission(ack, body, client, view, logger):
2424
# Assume there's an input block with `block_c` as the block_id and `dreamy_input`
2525
hopes_and_dreams = view["state"]["values"]["block_c"]["dreamy_input"]
2626
user = body["user"]["id"]
@@ -44,8 +44,11 @@ def handle_submission(ack, body, client, view):
4444
except Exception as e:
4545
# Handle error
4646
msg = "There was an error with your submission"
47-
finally:
48-
# Message the user
47+
48+
# Message the user
49+
try:
4950
client.chat_postMessage(channel=user, text=msg)
51+
except e:
52+
logger.exception(f"Failed to post a message {e}")
5053
```
5154
</div>

0 commit comments

Comments
 (0)