Better handling of stack trace report on 500 error

This commit is contained in:
allegroai 2021-07-25 14:39:59 +03:00
parent 158da9b480
commit 6488dc54e6
4 changed files with 12 additions and 4 deletions

View File

@ -57,6 +57,7 @@ class AuthBLL:
api_version=str(ServiceRepo.max_endpoint_version()),
server_version=str(get_version()),
server_build=str(get_build_number()),
feature_set="basic",
)
return GetTokenResponse(token=token.decode("ascii"))

View File

@ -3,7 +3,7 @@
debug: false # Debug mode
pretty_json: false # prettify json response
return_stack: true # return stack trace on error
log_calls: true # Log API Calls
return_stack_to_caller: true # top-level control on whether to return stack trace in an API response
# if 'return_stack' is true and error contains a status code, return stack trace only for these status codes
# valid values are:

View File

@ -588,13 +588,18 @@ class APICall(DataContainer):
self._end_ts = time.time()
self._duration = int((self._end_ts - self._start_ts) * 1000)
def get_response(self, include_stack: bool = False) -> Tuple[Union[dict, str], str]:
def get_response(self, include_stack: bool = None) -> Tuple[Union[dict, str], str]:
"""
Get the response for this call.
:param include_stack: If True, stack trace stored in this call's result should
be included in the response (default is False)
be included in the response (default follows configuration)
:return: Response data (encoded according to self.content_type) and the data's content type
"""
include_stack = (
include_stack
if include_stack is not None
else config.get("apiserver.return_stack_to_caller", False)
)
def make_version_number(version: PartialVersion) -> Union[None, float, str]:
"""

View File

@ -10,6 +10,7 @@ def extract_properties_to_lists(
key_names: Sequence[str],
data: Sequence[dict],
extract_func: Optional[Callable[[dict], Tuple]] = None,
target_keys: Optional[Sequence[str]] = None,
) -> dict:
"""
Given a list of dictionaries and names of dictionary keys
@ -20,9 +21,10 @@ def extract_properties_to_lists(
:param extract_func: the optional callable that extracts properties
from a dictionary and put them in a tuple in the order corresponding to
key_names. If not specified then properties are extracted according to key_names
:param target_keys: optional alternative keys to use in the target dictionary. must be equal in length to key_names.
"""
if not data:
return {k: [] for k in key_names}
value_sequences = zip(*map(extract_func or itemgetter(*key_names), data))
return dict(zip(key_names, map(list, value_sequences)))
return dict(zip((target_keys or key_names), map(list, value_sequences)))