(
self,
endpoint_url,
headers,
payload,
run_state: Optional[RunState],
num_retries: int = MAX_RETRIES,
silent: bool = False,
)
| 114 | raise exception_class(message) |
| 115 | |
| 116 | def post_request( |
| 117 | self, |
| 118 | endpoint_url, |
| 119 | headers, |
| 120 | payload, |
| 121 | run_state: Optional[RunState], |
| 122 | num_retries: int = MAX_RETRIES, |
| 123 | silent: bool = False, |
| 124 | ): |
| 125 | if run_state is not None: |
| 126 | self._extend_payload_with_run_state(payload, run_state) |
| 127 | |
| 128 | retry_delay = RETRY_DELAY |
| 129 | response_json = None |
| 130 | |
| 131 | for attempt in range(num_retries + 1): |
| 132 | try: |
| 133 | response = requests.post(endpoint_url, headers=headers, json=payload) |
| 134 | |
| 135 | try: |
| 136 | response_json = response.json() |
| 137 | except requests.exceptions.JSONDecodeError as e: |
| 138 | self.console.debug(f"Failed to decode JSON response: {e}. Response text: {response.text}") |
| 139 | raise Exception(f"Error rendering plain code: Failed to decode API response ({e}).\n") from e |
| 140 | |
| 141 | if response.status_code == requests.codes.bad_request and "error_code" in response_json: |
| 142 | self._raise_for_error_code(response_json) |
| 143 | |
| 144 | response.raise_for_status() |
| 145 | return response_json |
| 146 | |
| 147 | except Exception as e: |
| 148 | # For other errors, check if they should be retried |
| 149 | if response_json is not None and "error_code" in response_json: |
| 150 | if response_json["error_code"] not in RETRY_ERROR_CODES: |
| 151 | raise e |
| 152 | |
| 153 | retry_delay = self._handle_retry_logic(attempt, retry_delay, num_retries, e, silent) |
| 154 | |
| 155 | def connection_check(self, client_version): |
| 156 | endpoint_url = f"{self.api_url}/connection_check" |
no test coverage detected