Skip to content

Commit

Permalink
Merge pull request #11 from onna/error-response
Browse files Browse the repository at this point in the history
- Handle auth validation errors gracefully
  • Loading branch information
Ismael Alaoui authored Apr 4, 2019
2 parents 9de6d05 + b6a53fd commit 45d9243
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2.0.4 (2019-4-4)
-----------------

- Handle auth validation errors gracefully

2.0.3 (2018-10-3)
-----------------

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.3
2.0.4
29 changes: 17 additions & 12 deletions guillotina_oauth/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,18 +563,23 @@ async def call_auth(self, url, params, headers={}, future=None,
result = await resp.json()
if resp.status != 200:
# handle the error...
text = await resp.text()
if resp.status == 484 and not retry: # bad service token status code
logger.error('Invalid service token, refreshing')
# try to get new one and retry this...
await self.refresh_service_token()
await resp.release()
await session.close()
return await self.call_auth(url, params, headers=headers,
future=future, retry=True, **kw)
else:
logger.error(
f'OAUTH SERVER ERROR({url}) {resp.status} {text}')

try:
text = await resp.text()
if resp.status == 484 and not retry: # bad service token status code
logger.error('Invalid service token, refreshing')
# try to get new one and retry this...
await self.refresh_service_token()
await resp.release()
await session.close()
return await self.call_auth(url, params, headers=headers,
future=future, retry=True, **kw)
else:
logger.error(
f'OAUTH SERVER ERROR({url}) {resp.status} {text}')
except Exception:
logger.error(f'OAUTH SERVER ERROR({url}) {resp.status}')

await resp.release()
await session.close()
if future is not None:
Expand Down

0 comments on commit 45d9243

Please sign in to comment.