-
Notifications
You must be signed in to change notification settings - Fork 22
[Chore] Log errors from cf-api for better debugging #283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a7d3d97
log errors (json, strings) from cf-api for better debugging
mohammedahmed18 a263a5e
log status code on failed cf-api calls
mohammedahmed18 57d700b
more detailed log error message
mohammedahmed18 3952776
Merge branch 'main' into chore/handle-json-and-string-errors-from-cfapi
Saga4 abe3017
Merge branch 'main' into chore/handle-json-and-string-errors-from-cfapi
mohammedahmed18 4bd757b
Merge branch 'main' into chore/handle-json-and-string-errors-from-cfapi
Saga4 5ba5445
Merge branch 'main' into chore/handle-json-and-string-errors-from-cfapi
Saga4 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,13 +45,31 @@ def make_cfapi_request( | |
| cfapi_headers = {"Authorization": f"Bearer {get_codeflash_api_key()}"} | ||
| if extra_headers: | ||
| cfapi_headers.update(extra_headers) | ||
| if method.upper() == "POST": | ||
| json_payload = json.dumps(payload, indent=None, default=pydantic_encoder) | ||
| cfapi_headers["Content-Type"] = "application/json" | ||
| response = requests.post(url, data=json_payload, headers=cfapi_headers, timeout=60) | ||
| else: | ||
| response = requests.get(url, headers=cfapi_headers, timeout=60) | ||
| return response | ||
| try: | ||
| if method.upper() == "POST": | ||
| json_payload = json.dumps(payload, indent=None, default=pydantic_encoder) | ||
| cfapi_headers["Content-Type"] = "application/json" | ||
| response = requests.post(url, data=json_payload, headers=cfapi_headers, timeout=60) | ||
| else: | ||
| response = requests.get(url, headers=cfapi_headers, timeout=60) | ||
| response.raise_for_status() | ||
| return response # noqa: TRY300 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Q: whats noqa? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's for ignoring ruff linter for this line. |
||
| except requests.exceptions.HTTPError: | ||
| # response may be either a string or JSON, so we handle both cases | ||
| error_message = "" | ||
| try: | ||
| json_response = response.json() | ||
| if "error" in json_response: | ||
| error_message = json_response["error"] | ||
| elif "message" in json_response: | ||
| error_message = json_response["message"] | ||
| except (ValueError, TypeError): | ||
| error_message = response.text | ||
|
|
||
| logger.error( | ||
| f"CF_API_Error:: making request to Codeflash API (url: {url}, method: {method}, status {response.status_code}): {error_message}" | ||
| ) | ||
| return response | ||
|
|
||
|
|
||
| @lru_cache(maxsize=1) | ||
|
|
@@ -165,10 +183,7 @@ def is_github_app_installed_on_repo(owner: str, repo: str) -> bool: | |
| :return: The response object. | ||
| """ | ||
| response = make_cfapi_request(endpoint=f"/is-github-app-installed?repo={repo}&owner={owner}", method="GET") | ||
| if not response.ok or response.text != "true": | ||
| logger.error(f"Error: {response.text}") | ||
| return False | ||
| return True | ||
| return response.ok and response.text == "true" | ||
|
|
||
|
|
||
| def get_blocklisted_functions() -> dict[str, set[str]] | dict[str, Any]: | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good.