|
2 | 2 | import datetime
|
3 | 3 | import hashlib
|
4 | 4 | import json
|
| 5 | +import logging |
5 | 6 | import os
|
6 | 7 | import time
|
7 | 8 | import typing
|
|
28 | 29 | # Todo: think about splitting in to PagerdutyIncidentsProvider and PagerdutyAlertsProvider
|
29 | 30 | # Read this: https://community.pagerduty.com/forum/t/create-incident-using-python/3596/3
|
30 | 31 |
|
| 32 | +logger = logging.getLogger(__name__) |
| 33 | + |
31 | 34 |
|
32 | 35 | @pydantic.dataclasses.dataclass
|
33 | 36 | class PagerdutyProviderAuthConfig:
|
@@ -248,16 +251,25 @@ def oauth2_logic(**payload) -> dict:
|
248 | 251 | "grant_type": "authorization_code",
|
249 | 252 | }
|
250 | 253 |
|
| 254 | + access_token_response = requests.post( |
| 255 | + url=f"{PagerdutyProvider.BASE_OAUTH_URL}/oauth/token", |
| 256 | + data=access_token_params, |
| 257 | + headers={"Content-Type": "application/x-www-form-urlencoded"}, |
| 258 | + ) |
251 | 259 | try:
|
252 |
| - access_token_response = requests.post( |
253 |
| - url=f"{PagerdutyProvider.BASE_OAUTH_URL}/oauth/token", |
254 |
| - data=access_token_params, |
255 |
| - headers={"Content-Type": "application/x-www-form-urlencoded"}, |
256 |
| - ) |
257 | 260 | access_token_response.raise_for_status()
|
258 | 261 | access_token_response = access_token_response.json()
|
259 |
| - except Exception as e: |
260 |
| - raise Exception(e) |
| 262 | + except Exception: |
| 263 | + response_text = access_token_response.text |
| 264 | + response_status = access_token_response.status_code |
| 265 | + logger.exception( |
| 266 | + "Failed to get access token", |
| 267 | + extra={ |
| 268 | + "response_text": response_text, |
| 269 | + "response_status": response_status, |
| 270 | + }, |
| 271 | + ) |
| 272 | + raise |
261 | 273 |
|
262 | 274 | access_token = access_token_response.get("access_token")
|
263 | 275 | if not access_token:
|
|
0 commit comments