|
5 | 5 | import warnings
|
6 | 6 | from contextlib import contextmanager
|
7 | 7 | from pathlib import Path
|
8 |
| -from typing import Optional, Tuple |
| 8 | +from typing import Optional, Tuple, Union |
9 | 9 |
|
10 | 10 | import aiofiles
|
11 | 11 | from aiohttp import ClientPayloadError, ClientSession, ClientTimeout
|
@@ -69,14 +69,21 @@ def api_client():
|
69 | 69 | del client
|
70 | 70 |
|
71 | 71 |
|
72 |
| -def _handle_api_exception(store_id: str, err: ApiException): |
| 72 | +def _handle_api_exception(store_id: Union[int, str], err: ApiException): |
| 73 | + """ Maps client's ApiException -> NodeportsException """ |
| 74 | + |
| 75 | + # NOTE: ApiException produces a long __str__ with multiple lines which is not |
| 76 | + # allowed when composing header |
| 77 | + # SEE https://github.com/tornadoweb/tornado/blob/master/tornado/http1connection.py#L456 |
| 78 | + error_reason: str = err.reason.replace("\n", "-") |
| 79 | + |
73 | 80 | if err.status > 399 and err.status < 500:
|
74 | 81 | # something invalid
|
75 |
| - raise exceptions.StorageInvalidCall(err) |
| 82 | + raise exceptions.StorageInvalidCall(error_reason) |
76 | 83 | if err.status > 499:
|
77 | 84 | # something went bad inside the storage server
|
78 |
| - raise exceptions.StorageServerIssue(err) |
79 |
| - raise exceptions.StorageConnectionError(store_id, err) |
| 85 | + raise exceptions.StorageServerIssue(error_reason) |
| 86 | + raise exceptions.StorageConnectionError(store_id, error_reason) |
80 | 87 |
|
81 | 88 |
|
82 | 89 | async def _get_location_id_from_location_name(store: str, api: UsersApi):
|
|
0 commit comments