Skip to content

Commit 977875e

Browse files
authored
Improve the error message in the case where AuthorizeResult is not found (#476)
1 parent 4e0709f commit 977875e

File tree

4 files changed

+38
-5
lines changed

4 files changed

+38
-5
lines changed

slack_bolt/authorization/async_authorize.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717

1818
class AsyncAuthorize:
19+
"""This provides authorize function that returns AuthorizeResult
20+
for an incoming request from Slack."""
21+
1922
def __init__(self):
2023
pass
2124

@@ -31,6 +34,10 @@ async def __call__(
3134

3235

3336
class AsyncCallableAuthorize(AsyncAuthorize):
37+
"""When you pass the authorize argument in AsyncApp constructor,
38+
This authorize implementation will be used.
39+
"""
40+
3441
def __init__(
3542
self, *, logger: Logger, func: Callable[..., Awaitable[AuthorizeResult]]
3643
):
@@ -93,6 +100,11 @@ async def __call__(
93100

94101

95102
class AsyncInstallationStoreAuthorize(AsyncAuthorize):
103+
"""If you use the OAuth flow settings, this authorize implementation will be used.
104+
As long as your own InstallationStore (or the built-in ones) works as you expect,
105+
you can expect that the authorize layer should work for you without any customization.
106+
"""
107+
96108
authorize_result_cache: Dict[str, AuthorizeResult]
97109
find_installation_available: Optional[bool]
98110
find_bot_available: Optional[bool]

slack_bolt/authorization/authorize.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import inspect
2-
import os
32
from logging import Logger
43
from typing import Optional, Callable, Dict, Any
54

@@ -16,6 +15,9 @@
1615

1716

1817
class Authorize:
18+
"""This provides authorize function that returns AuthorizeResult
19+
for an incoming request from Slack."""
20+
1921
def __init__(self):
2022
pass
2123

@@ -31,6 +33,10 @@ def __call__(
3133

3234

3335
class CallableAuthorize(Authorize):
36+
"""When you pass the authorize argument in AsyncApp constructor,
37+
This authorize implementation will be used.
38+
"""
39+
3440
def __init__(
3541
self,
3642
*,
@@ -96,6 +102,11 @@ def __call__(
96102

97103

98104
class InstallationStoreAuthorize(Authorize):
105+
"""If you use the OAuth flow settings, this authorize implementation will be used.
106+
As long as your own InstallationStore (or the built-in ones) works as you expect,
107+
you can expect that the authorize layer should work for you without any customization.
108+
"""
109+
99110
authorize_result_cache: Dict[str, AuthorizeResult]
100111
bot_only: bool
101112
find_installation_available: bool

slack_bolt/middleware/authorization/async_multi_teams_authorization.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,13 @@ async def async_process(
6262
req.context.client.token = token
6363
return await next()
6464
else:
65-
# Just in case
66-
self.logger.error("auth.test API call result is unexpectedly None")
65+
# This situation can arise if:
66+
# * A developer installed the app from the "Install to Workspace" button in Slack app config page
67+
# * The InstallationStore failed to save or deleted the installation for this workspace
68+
self.logger.error(
69+
"Although the app should be installed into this workspace, "
70+
"the AuthorizeResult (returned value from authorize) for it was not found."
71+
)
6772
return _build_error_response()
6873

6974
except SlackApiError as e:

slack_bolt/middleware/authorization/multi_teams_authorization.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,13 @@ def process(
6767
req.context.client.token = token
6868
return next()
6969
else:
70-
# Just in case
71-
self.logger.error("auth.test API call result is unexpectedly None")
70+
# This situation can arise if:
71+
# * A developer installed the app from the "Install to Workspace" button in Slack app config page
72+
# * The InstallationStore failed to save or deleted the installation for this workspace
73+
self.logger.error(
74+
"Although the app should be installed into this workspace, "
75+
"the AuthorizeResult (returned value from authorize) for it was not found."
76+
)
7277
return _build_error_response()
7378

7479
except SlackApiError as e:

0 commit comments

Comments
 (0)