31
31
import datetime
32
32
import os
33
33
import requests
34
+ import sys
34
35
import time
36
+ import traceback
35
37
38
+ TIMEOUT = 60
36
39
37
40
def _fix_url (url ):
38
41
if url .startswith ("/" ):
@@ -57,7 +60,17 @@ def _fix_kwargs(kwargs):
57
60
return kwargs
58
61
59
62
def 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" )
61
74
if "X-RateLimit-Remaining" in response .headers :
62
75
remaining = int (response .headers ["X-RateLimit-Remaining" ])
63
76
if remaining <= 1 :
@@ -78,13 +91,41 @@ def get(url, **kwargs):
78
91
return response
79
92
80
93
def 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" )
82
102
83
103
def 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" )
85
112
86
113
def 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" )
88
122
89
123
def 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