1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-30 19:23:07 +03:00

fix(cmapi): MCOL-5962 Fix rollback in mcs cli and passing errors during broadcasting config

* fix(cmapi): ClusterControllerClient request error handling
* fix(cmapi): broadcast_new_config request error handling
* style(cmapi): logs
This commit is contained in:
mariadb-AlanMologorsky
2025-04-04 15:08:32 +03:00
committed by Alan Mologorsky
parent f04b189476
commit 10dec6ea94
3 changed files with 42 additions and 10 deletions

View File

@ -1,12 +1,14 @@
import requests
import logging
from typing import Any, Dict, Optional, Union
import pyotp
import requests
from cmapi_server.controllers.dispatcher import _version
from cmapi_server.constants import (
CMAPI_CONF_PATH, CURRENT_NODE_CMAPI_URL, SECRET_KEY,
)
from cmapi_server.exceptions import CMAPIBasicError
from cmapi_server.helpers import get_config_parser, get_current_key
@ -146,5 +148,28 @@ class ClusterControllerClient:
response.raise_for_status()
return response.json()
# TODO: different handler for timeout exception?
except requests.exceptions.RequestException as e:
return {'error': str(e)}
except requests.HTTPError as exc:
resp = exc.response
error_msg = str(exc)
if resp.status_code == 422:
# in this case we think cmapi server returned some value but
# had error during running endpoint handler code
try:
resp_json = response.json()
error_msg = resp_json.get('error', resp_json)
except requests.exceptions.JSONDecodeError:
error_msg = response.text
message = (
f'API client got an exception in request to {exc.request.url} '
f'with code {resp.status_code} and error: {error_msg}'
)
logging.error(message)
raise CMAPIBasicError(message)
except requests.exceptions.RequestException as exc:
message = (
'API client got an undefined error in request to '
f'{exc.request.url} with code {exc.response.status_code} and '
f'error: {str(exc)}'
)
logging.error(message)
raise CMAPIBasicError(message)