Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
a908992
Improve error handling and exception message presentation
Jul 9, 2026
eabf06c
refactor: improve error handling consistency and preserve original AP…
Jul 10, 2026
58e8f04
Fix CLI output handling to support both dict and object formats
Jul 13, 2026
1755866
Fix CLI output handling to support both dict and object formats
Jul 13, 2026
49f03c6
Merge branch 'main' into dev/errors
lzsweb Jul 13, 2026
fc1d296
fix: replace last remaining code='Unknown' with http_{status} in asyn…
Jul 13, 2026
2fe1241
refactor: unify error response handling and improve error code flexib…
Jul 15, 2026
032637d
feat: add centralized error registry and improve internal error handling
Jul 16, 2026
eafd429
feat: add centralized error registry and improve internal error handling
Jul 16, 2026
bee28b9
feat: add centralized error registry and improve internal error handling
Jul 16, 2026
f45a27b
refactor(cli): keep error codes in original camelCase format
Jul 17, 2026
67cc1ee
refactor: split _build_api_request to reduce statement count
Jul 17, 2026
5e201ac
fix: correct WebSocket URL scheme and fix lint errors
Jul 17, 2026
712d959
feat: enhance error handling for invalid URLs and authentication fail…
Jul 17, 2026
ffc401c
refactor: improve WebSocket error handling and cleanup unused code
Jul 22, 2026
5833cf5
fix: isolate AgenticRL internal error codes from public SDK API
Jul 28, 2026
3b1296d
feat: unify agentstudio error codes onto the centralized registry
foleydang Jul 28, 2026
dd5c016
refactor(agentic_rl): replace internal exception conversion with stan…
Jul 28, 2026
0c576c3
refactor(agentic_rl): replace custom exception conversion with standa…
Jul 28, 2026
565763d
refactor: unify error handling with centralized error registry
Jul 30, 2026
133c8e3
refactor: unify error handling with centralized error registry
Jul 30, 2026
2e7721e
feat(agentic-rl): add dedicated error definitions and align error cod…
Aug 4, 2026
bc88844
refactor: rename AGENTIC_RL error constants to CLIENT prefix and add …
Aug 5, 2026
1958e6e
refactor: rename AGENTIC_RL error constants to CLIENT prefix and add …
Aug 5, 2026
c49ef90
refactor: rename AGENTIC_RL error constants to CLIENT prefix and add …
Aug 5, 2026
f355c97
refactor: rename client error definitions and separate client errors …
Aug 5, 2026
aa178a3
refactor: rename SDK error codes from "sdk.*" to "agentic_rl.*" prefix
Aug 5, 2026
487ce64
fix: add SDK_ prefix to agentic_rl error definitions
Aug 6, 2026
2f3b45b
Merge branch 'main' into dev/errors
lzsweb Aug 6, 2026
d545ab9
fix: fill in AgenticRL error solutions and fix HTTP request bugs
Aug 6, 2026
72401b1
fix: fill in AgenticRL error solutions and fix HTTP request bugs
Aug 6, 2026
8d915c2
refactor: remove redundant ClientErrorDef class and unused gateway er…
Aug 7, 2026
9bac4d7
refactor: back agentstudio transport/stream error codes with the regi…
foleydang Aug 7, 2026
97af92c
refactor: classify agentstudio status errors by server code only
foleydang Aug 7, 2026
40b34b6
refactor: classify agentstudio status errors by server code only
foleydang Aug 7, 2026
2a974b5
Merge remote-tracking branch 'origin/dev/errors' into dev/errors
Aug 10, 2026
707b7a7
fix: declare missing dependencies for reinforcement module
Aug 19, 2026
c07e68d
Merge remote-tracking branch 'origin/main' into dev/errors
Aug 19, 2026
2628ad4
Merge remote-tracking branch 'origin/dev/errors' into dev/errors
Aug 19, 2026
0166804
refactor: simplify agentstudio exception handling and unify agentic…
Aug 19, 2026
afeda76
fix(agentstudio): use INTERNAL_ERROR constant for fallback error code
Aug 20, 2026
accf4a9
refactor(error_registry): remove hardcoded URLs and fix line length
Aug 20, 2026
2caf3b2
feat(error_registry): restore explicit URLs in solution messages
Aug 21, 2026
8fdb44a
fix(error_registry): resolve line-length and pylint warnings
Aug 31, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 14 additions & 38 deletions dashscope/api_entities/aiohttp_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
)
from dashscope.common.error import UnsupportedHTTPMethod
from dashscope.common.logging import logger
from dashscope.common.utils import async_to_sync
from dashscope.common.utils import (
async_to_sync,
_handle_aiohttp_failed_response,
)


class AioHttpRequest(AioBaseRequest):
Expand Down Expand Up @@ -162,19 +165,24 @@ async def _handle_response( # pylint: disable=too-many-branches
if "request_id" in msg:
request_id = msg["request_id"]
except json.JSONDecodeError:
msg = None
yield DashScopeAPIResponse(
request_id=request_id,
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
code="Unknown",
code=None,
Comment thread
luk384090-cloud marked this conversation as resolved.
Outdated
message=data,
)
continue
if is_error:
if is_error and msg is not None:
yield DashScopeAPIResponse(
request_id=request_id,
status_code=status_code,
code=msg["code"],
message=msg["message"],
code=msg.get("code")
or msg.get("error_code")
or f"http_{status_code}",
message=msg.get("message")
or msg.get("error_message")
or f"HTTP {status_code} error",
)
else:
yield DashScopeAPIResponse(
Expand Down Expand Up @@ -219,39 +227,7 @@ async def _handle_response( # pylint: disable=too-many-branches
usage=usage,
)
else:
if "application/json" in response.content_type:
error = await response.json()
if "request_id" in error:
request_id = error["request_id"]
if "message" not in error:
message = ""
logger.error(
"Request: %s failed, status: %s",
self.url,
response.status,
)
else:
message = error["message"]
logger.error(
"Request: %s failed, status: %s, message: %s",
self.url,
response.status,
error["message"],
)
yield DashScopeAPIResponse(
request_id=request_id,
status_code=response.status,
code=error["code"],
message=message,
)
else:
msg = await response.read()
yield DashScopeAPIResponse(
request_id=request_id,
status_code=response.status,
code="Unknown",
message=msg.decode("utf-8"),
)
yield _handle_aiohttp_failed_response(response)

# pylint: disable=too-many-branches
async def _handle_request(self):
Expand Down
34 changes: 22 additions & 12 deletions dashscope/api_entities/http_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,10 @@ async def _handle_aio_request(self): # pylint: disable=too-many-branches
if should_close:
await session.close()
except Exception as e:
logger.debug(e)
raise e
logger.error(f"Async request failed: {e}", exc_info=True)
from dashscope.common.error import DashScopeException

raise DashScopeException(str(e)) from e

@staticmethod
def __handle_parameters(params: dict) -> dict:
Expand Down Expand Up @@ -291,7 +293,7 @@ async def _handle_aio_response( # pylint: disable=too-many-branches, too-many-s
yield DashScopeAPIResponse(
request_id=request_id,
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
code="Unknown",
code=None,
Comment thread
luk384090-cloud marked this conversation as resolved.
Outdated
message=data,
headers=headers,
)
Expand All @@ -300,8 +302,12 @@ async def _handle_aio_response( # pylint: disable=too-many-branches, too-many-s
yield DashScopeAPIResponse(
request_id=request_id,
status_code=status_code,
code=msg["code"],
message=msg["message"],
code=msg.get("code")
or msg.get("error_code")
or f"http_{status_code}",
message=msg.get("message")
or msg.get("error_message")
or f"HTTP {status_code} error",
headers=headers,
)
else:
Expand Down Expand Up @@ -401,7 +407,7 @@ def _handle_response( # pylint: disable=too-many-branches
request_id=request_id,
status_code=HTTPStatus.BAD_REQUEST,
output=None,
code="Unknown",
code=None,
Comment thread
luk384090-cloud marked this conversation as resolved.
Outdated
message=data,
headers=headers,
)
Expand All @@ -411,10 +417,12 @@ def _handle_response( # pylint: disable=too-many-branches
request_id=request_id,
status_code=status_code,
output=None,
code=msg["code"]
if "code" in msg
else None, # noqa E501
message=msg["message"] if "message" in msg else None,
code=msg.get("code")
or msg.get("error_code")
or f"http_{status_code}",
message=msg.get("message")
or msg.get("error_message")
or f"HTTP {status_code} error",
headers=headers,
) # noqa E501
else:
Expand Down Expand Up @@ -517,5 +525,7 @@ def _handle_request(self): # pylint: disable=too-many-branches
if should_close:
session.close()
except Exception as e:
logger.debug(e)
raise e
logger.error(f"Sync request failed: {e}", exc_info=True)
from dashscope.common.error import DashScopeException

raise DashScopeException(str(e)) from e
37 changes: 29 additions & 8 deletions dashscope/api_entities/websocket_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ async def aio_call(self):
pass
return result

async def connection_handler(self): # pylint: disable=too-many-branches
async def connection_handler(
Comment thread
luk384090-cloud marked this conversation as resolved.
self,
): # pylint: disable=too-many-branches,too-many-statements
try:
task_id = None
async with aiohttp.ClientSession(
Expand Down Expand Up @@ -203,26 +205,45 @@ async def connection_handler(self): # pylint: disable=too-many-branches
)
except aiohttp.WSServerHandshakeError as e:
code = e.status
msg = e.message
original_msg = e.message or ""

if e.status in [HTTPStatus.FORBIDDEN, HTTPStatus.UNAUTHORIZED]:
msg = "Unauthorized, your api-key is invalid!"
friendly_hint = "Unauthorized, your api-key may be invalid!"
Comment thread
luk384090-cloud marked this conversation as resolved.
Outdated
msg = (
f"{friendly_hint} (Server details: {original_msg})"
if original_msg
else friendly_hint
)
elif e.status == HTTPStatus.SERVICE_UNAVAILABLE:
msg = SERVICE_503_MESSAGE
friendly_hint = SERVICE_503_MESSAGE
Comment thread
luk384090-cloud marked this conversation as resolved.
Outdated
msg = (
f"{friendly_hint} (Server details: {original_msg})"
if original_msg
else friendly_hint
)
else:
pass
msg = (
Comment thread
luk384090-cloud marked this conversation as resolved.
Outdated
original_msg
or f"WebSocket handshake failed with status {e.status}"
)

# Note: For WebSocket handshake errors, code uses format
# "WS_HANDSHAKE_{status_code}" to distinguish from business errors.
# This is a special case.
yield DashScopeAPIResponse(
Comment thread
luk384090-cloud marked this conversation as resolved.
Outdated
request_id=task_id,
status_code=code,
code=code,
code=f"WS_HANDSHAKE_{code}" if code else "WS_HANDSHAKE_FAILED",
Comment thread
luk384090-cloud marked this conversation as resolved.
Outdated
message=msg,
)
except BaseException as e:
logger.exception(e)
exception_name = type(e).__name__
yield DashScopeAPIResponse(
request_id="",
status_code=-1,
code="Unknown",
message=f"Error type: {type(e)}, message: {e}",
code="",
Comment thread
luk384090-cloud marked this conversation as resolved.
Outdated
message=f"[SDK Internal Error] {exception_name}: {e}",
)

def _to_DashScopeAPIResponse(self, task_id, is_binary, result):
Expand Down
Loading
Loading