3131import datetime
3232import os
3333import requests
34+ import sys
3435import time
36+ import traceback
3537
38+ TIMEOUT = 60
3639
3740def _fix_url (url ):
3841 if url .startswith ("/" ):
@@ -57,7 +60,17 @@ def _fix_kwargs(kwargs):
5760 return kwargs
5861
5962def get (url , ** kwargs ):
60- response = requests .get (_fix_url (url ), timeout = 30 , ** _fix_kwargs (kwargs ))
63+ ok = True
64+ try :
65+ response = requests .get (_fix_url (url ), timeout = TIMEOUT , ** _fix_kwargs (kwargs ))
66+ except Exception as e :
67+ exception_text = traceback .format_exc ()
68+ if "ADABOT_GITHUB_ACCESS_TOKEN" in os .environ :
69+ exception_text = exception_text .replace (os .environ ["ADABOT_GITHUB_ACCESS_TOKEN" ], "[secure]" )
70+ print (exception_text , file = sys .stderr )
71+ ok = False
72+ if not ok :
73+ raise RuntimeError ("See print for error text that as been sanitized for secrets" )
6174 if "X-RateLimit-Remaining" in response .headers :
6275 remaining = int (response .headers ["X-RateLimit-Remaining" ])
6376 if remaining <= 1 :
@@ -78,13 +91,41 @@ def get(url, **kwargs):
7891 return response
7992
8093def post (url , ** kwargs ):
81- return requests .post (_fix_url (url ), timeout = 30 , ** _fix_kwargs (kwargs ))
94+ try :
95+ return requests .post (_fix_url (url ), timeout = TIMEOUT , ** _fix_kwargs (kwargs ))
96+ except Exception as e :
97+ exception_text = traceback .format_exc ()
98+ if "ADABOT_GITHUB_ACCESS_TOKEN" in os .environ :
99+ exception_text = exception_text .replace (os .environ ["ADABOT_GITHUB_ACCESS_TOKEN" ], "[secure]" )
100+ print (exception_text , file = sys .stderr )
101+ raise RuntimeError ("See print for error text that as been sanitized for secrets" )
82102
83103def put (url , ** kwargs ):
84- return requests .put (_fix_url (url ), timeout = 30 , ** _fix_kwargs (kwargs ))
104+ try :
105+ return requests .put (_fix_url (url ), timeout = TIMEOUT , ** _fix_kwargs (kwargs ))
106+ except Exception as e :
107+ exception_text = traceback .format_exc ()
108+ if "ADABOT_GITHUB_ACCESS_TOKEN" in os .environ :
109+ exception_text = exception_text .replace (os .environ ["ADABOT_GITHUB_ACCESS_TOKEN" ], "[secure]" )
110+ print (exception_text , file = sys .stderr )
111+ raise RuntimeError ("See print for error text that as been sanitized for secrets" )
85112
86113def patch (url , ** kwargs ):
87- return requests .patch (_fix_url (url ), timeout = 30 , ** _fix_kwargs (kwargs ))
114+ try :
115+ return requests .patch (_fix_url (url ), timeout = TIMEOUT , ** _fix_kwargs (kwargs ))
116+ except Exception as e :
117+ exception_text = traceback .format_exc ()
118+ if "ADABOT_GITHUB_ACCESS_TOKEN" in os .environ :
119+ exception_text = exception_text .replace (os .environ ["ADABOT_GITHUB_ACCESS_TOKEN" ], "[secure]" )
120+ print (exception_text , file = sys .stderr )
121+ raise RuntimeError ("See print for error text that as been sanitized for secrets" )
88122
89123def delete (url , ** kwargs ):
90- return requests .delete (_fix_url (url ), timeout = 30 , ** _fix_kwargs (kwargs ))
124+ try :
125+ return requests .delete (_fix_url (url ), timeout = TIMEOUT , ** _fix_kwargs (kwargs ))
126+ except Exception as e :
127+ exception_text = traceback .format_exc ()
128+ if "ADABOT_GITHUB_ACCESS_TOKEN" in os .environ :
129+ exception_text = exception_text .replace (os .environ ["ADABOT_GITHUB_ACCESS_TOKEN" ], "[secure]" )
130+ print (exception_text , file = sys .stderr )
131+ raise RuntimeError ("See print for error text that as been sanitized for secrets" )
0 commit comments