@@ -91,10 +91,12 @@ def search_code(
91
91
92
92
inner_tqdm = partial (tqdm , disable = not inner_progress , unit = "record" , leave = False )
93
93
94
- initial_response = _search_code_helper (page_size = page_size , page = page , query = query ).json ()
95
- total = initial_response ["total_count" ]
94
+ initial_res = _search_code_helper (page_size = page_size , page = page , query = query )
95
+ initial_res .raise_for_status ()
96
+ initial_res_json = initial_res .json ()
97
+ total = initial_res_json ["total_count" ]
96
98
total_pages = 1 + (total // page_size )
97
- yield from inner_tqdm (initial_response ["items" ], desc = "Page 1" )
99
+ yield from inner_tqdm (initial_res_json ["items" ], desc = "Page 1" )
98
100
99
101
with tqdm (
100
102
total = total_pages , unit = "page" , disable = not progress , desc = "Paginating code search results"
@@ -104,10 +106,10 @@ def search_code(
104
106
while page_size * page < total :
105
107
page += 1
106
108
tbar .update (1 )
107
- successive_response = _search_code_helper (
108
- page = page , page_size = page_size , query = query
109
- ) .json ()
110
- yield from inner_tqdm (successive_response ["items" ], desc = f"Page { page } " )
109
+ res = _search_code_helper (page = page , page_size = page_size , query = query )
110
+ res . raise_for_status ()
111
+ res_json = res .json ()
112
+ yield from inner_tqdm (res_json ["items" ], desc = f"Page { page } " )
111
113
112
114
113
115
def _search_code_helper (page_size : int , page : int , query : str ) -> requests .Response :
0 commit comments