Networking: Gate sending tracebacks over the API

It's possible that tracebacks can give too much info about a system
when sent over the API. Gate this under a flag to send them only
when debugging since this feature is still useful.

Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
kingbri 2024-07-13 17:59:58 -04:00
parent ddad422d8b
commit 6019c93637
2 changed files with 13 additions and 3 deletions

View file

@ -8,6 +8,9 @@ from loguru import logger
from pydantic import BaseModel
from typing import Optional
from common import config
from common.utils import unwrap
class TabbyRequestErrorMessage(BaseModel):
"""Common request error type."""
@ -33,15 +36,18 @@ def get_generator_error(message: str, exc_info: bool = True):
def handle_request_error(message: str, exc_info: bool = True):
"""Log a request error to the console."""
trace = traceback.format_exc()
send_trace = unwrap(config.network_config().get("send_tracebacks"), False)
error_message = TabbyRequestErrorMessage(
message=message, trace=traceback.format_exc()
message=message, trace=trace if send_trace else None
)
request_error = TabbyRequestError(error=error_message)
# Log the error and provided message to the console
if error_message.trace and exc_info:
logger.error(error_message.trace)
if trace and exc_info:
logger.error(trace)
logger.error(f"Sent to request: {message}")