Skip to content

Commit 0dbb2d7

Browse files
kalkinBahtiar Gadimov
authored andcommitted
log: GitHub provider add some error/warning logging
1 parent 4046d2b commit 0dbb2d7

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

glv/providers.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import os
66
import pathlib
77
import re
8-
import sys
8+
from datetime import datetime
99
from time import time
1010
from typing import Any, Optional, Tuple
1111

@@ -130,18 +130,22 @@ def provide(self, subject: str) -> str:
130130
headers=self._headers,
131131
)
132132
if request.status == 200:
133-
self._cache[subject] = json.loads(
134-
request.data.decode('utf-8'))['title'] + ' (#%s)' % _id
133+
LOG.debug('github-api: \ue27d #%s', _id)
134+
json_data = json.loads(request.data.decode('utf-8'))
135+
self._cache[subject] = json_data['title'] + ' (#%s)' % _id
135136
elif request.status == 401:
136-
print('Failed to authenticate', file=sys.stderr)
137+
LOG.error('github-api: ⛔ authentication failure')
137138
self.auth_failed = True
138139
return subject
139140
elif request.status == 403:
140141
self._rate_limit = int(
141142
request.headers['X-Ratelimit-Reset'])
143+
date = datetime.utcfromtimestamp(self._rate_limit)
144+
LOG.warning('github-api: ⚠ rate limited until %s', date)
142145
return subject
143146
else:
144-
print(request.data, file=sys.stderr)
147+
LOG.error('github-api ⛔ (%s) %s', request.status,
148+
request.data)
145149
return subject
146150

147151
return self._cache[subject]
@@ -205,7 +209,7 @@ def provide(self, subject: str) -> str:
205209
self._cache[subject] = json.loads(
206210
request.data.decode('utf-8'))['title'] + ' (#%s)' % _id
207211
elif request.status == 401:
208-
print('Failed to authenticate', file=sys.stderr)
212+
LOG.error('Failed to authenticate')
209213
self.auth_failed = True
210214
return subject
211215
else:

0 commit comments

Comments
 (0)