@@ -49,26 +49,17 @@ class MiningRequest(BaseModel):
4949async def root ():
5050 return {"message" : "Dashboard data-mining backend is on" }
5151
52- async def process_repo (repo : HttpUrl , requests : list [str ], responses : list , WIF_API : str = WIF_API_DEFAULT ):
52+ async def process_repo (repo : HttpUrl ,
53+ requests : list [str ],
54+ responses : list ,
55+ WIF_API : str = WIF_API_DEFAULT ):
5356 platform : str = repo .host .replace ("www." , "" )
5457 # If a custom Wikifactory API URL is provided, then use it.
5558 if WIF_API != WIF_API_DEFAULT :
56- try :
57- repo_info : dict = await supported_domains [platform ](repo , requests , WIF_API )
58- except exceptions .BadRepoError :
59- return JSONResponse (
60- status_code = status .HTTP_400_BAD_REQUEST ,
61- content = f"Error with repository: { repo } "
62- )
59+ repo_info : dict = await supported_domains [platform ](repo , requests , WIF_API )
6360 responses .append (repo_info )
6461 else :
65- try :
66- repo_info : dict = await supported_domains [platform ](repo , requests )
67- except exceptions .BadRepoError :
68- return JSONResponse (
69- status_code = status .HTTP_400_BAD_REQUEST ,
70- content = f"Error with repository: { repo } "
71- )
62+ repo_info : dict = await supported_domains [platform ](repo , requests )
7263 responses .append (repo_info )
7364
7465@app .post (
@@ -142,27 +133,27 @@ async def mining_request(request_body: MiningRequest):
142133 #
143134 # Construct, send API requests, and get results
144135 #
145-
146- await asyncio .gather (
147- * [
148- process_repo (
149- repo ,
150- request_body .requested_data ,
151- response_list ,
152- WIF_API = request_body .wikifactory_API_URL
153- ) for repo in request_body .repo_urls
154- ]
136+
137+ try :
138+ await asyncio .gather (
139+ * [
140+ process_repo (
141+ repo ,
142+ request_body .requested_data ,
143+ response_list ,
144+ WIF_API = request_body .wikifactory_API_URL
145+ ) for repo in request_body .repo_urls
146+ ]
147+ )
148+ except exceptions .BadGitHubTokenError :
149+ return JSONResponse (
150+ status_code = status .HTTP_500_INTERNAL_SERVER_ERROR ,
151+ content = f"Server-side GitHub API token incorrect or not in environment variable."
152+ )
153+ except exceptions .BadRepoError :
154+ return JSONResponse (
155+ status_code = status .HTTP_400_BAD_REQUEST ,
156+ content = f"Error with repository: { repo } "
155157 )
156-
157- # for repo in request_body.repo_urls:
158- # platform = repo.host.replace("www.", "")
159- # try:
160- # repo_info: dict = await supported_domains[platform](repo, request_body.requested_data)
161- # except exceptions.BadRepoError:
162- # return JSONResponse(
163- # status_code = status.HTTP_400_BAD_REQUEST,
164- # content = f"Error with repository: {repo}"
165- # )
166- # response_list.append(repo_info)
167158
168159 return response_list
0 commit comments