File tree Expand file tree Collapse file tree 2 files changed +52
-1
lines changed
Expand file tree Collapse file tree 2 files changed +52
-1
lines changed Original file line number Diff line number Diff line change @@ -60,7 +60,10 @@ def _build_callback_failure_response( # type: ignore
6060 )
6161 self ._logger .debug (debug_message )
6262
63- html = self ._redirect_uri_page_renderer .render_failure_page (reason )
63+ # Adding a bit more details to the error code to help installers understand what's happening.
64+ # This modification in the HTML page works only when developers use this built-in failure handler.
65+ detailed_error = build_detailed_error (reason )
66+ html = self ._redirect_uri_page_renderer .render_failure_page (detailed_error )
6467 return BoltResponse (
6568 status = status ,
6669 headers = {
@@ -126,3 +129,20 @@ def select_consistent_installation_store(
126129 else :
127130 # only oauth_flow_store is available
128131 return oauth_flow_store
132+
133+
134+ def build_detailed_error (reason : str ) -> str :
135+ if reason == "invalid_browser" :
136+ return (
137+ f"{ reason } : This can occur due to page reload, "
138+ "not beginning the OAuth flow from the valid starting URL, or "
139+ "the /slack/install URL not using https://"
140+ )
141+ elif reason == "invalid_state" :
142+ return f"{ reason } : The state parameter is no longer valid."
143+ elif reason == "missing_code" :
144+ return f"{ reason } : The code parameter is missing in this redirection."
145+ elif reason == "storage_error" :
146+ return f"{ reason } : The app's server encountered an issue. Contact the app developer."
147+ else :
148+ return f"{ reason } : This error code is returned from Slack. Refer to the documents for details."
Original file line number Diff line number Diff line change 1+ from slack_bolt .oauth .internals import build_detailed_error
2+
3+
4+ class TestOAuthInternals :
5+ def test_build_detailed_error_invalid_browser (self ):
6+ result = build_detailed_error ("invalid_browser" )
7+ assert result .startswith ("invalid_browser: This can occur due to page reload, " )
8+
9+ def test_build_detailed_error_invalid_state (self ):
10+ result = build_detailed_error ("invalid_state" )
11+ assert result .startswith (
12+ "invalid_state: The state parameter is no longer valid."
13+ )
14+
15+ def test_build_detailed_error_missing_code (self ):
16+ result = build_detailed_error ("missing_code" )
17+ assert result .startswith (
18+ "missing_code: The code parameter is missing in this redirection."
19+ )
20+
21+ def test_build_detailed_error_storage_error (self ):
22+ result = build_detailed_error ("storage_error" )
23+ assert result .startswith (
24+ "storage_error: The app's server encountered an issue. Contact the app developer."
25+ )
26+
27+ def test_build_detailed_error_others (self ):
28+ result = build_detailed_error ("access_denied" )
29+ assert result .startswith (
30+ "access_denied: This error code is returned from Slack. Refer to the documents for details."
31+ )
You can’t perform that action at this time.
0 commit comments