# Copyright 2025 - Oumi## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.importaiohttp_NON_RETRIABLE_STATUS_CODES={400,# Bad Request401,# Unauthorized403,# Forbidden404,# Not Found422,# Unprocessable Entity}
[docs]defis_non_retriable_status_code(status_code:int)->bool:"""Check if a status code is non-retriable."""returnstatus_codein_NON_RETRIABLE_STATUS_CODES
[docs]asyncdefget_failure_reason_from_response(response:aiohttp.ClientResponse,)->str:"""Return a string describing the error from the provided response."""try:response_json=awaitresponse.json()ifisinstance(response_json,list):response_json=response_json[0]error_msg=(response_json.get("error",{}).get("message")ifresponse_jsonelsef"HTTP {response.status}")exceptException:error_msg=f"HTTP {response.status}"returnerror_msg