Skip to content

Commit 2cd314b

Browse files
committed
refactor(error_handler): implement structured logging for errors
1 parent 7fafbab commit 2cd314b

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

linkedin_mcp_server/drivers/chrome.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,6 @@
1010
from typing import Dict, Optional
1111

1212
import inquirer # type: ignore
13-
from selenium import webdriver
14-
from selenium.common.exceptions import WebDriverException
15-
from selenium.webdriver.chrome.options import Options
16-
from selenium.webdriver.chrome.service import Service
17-
18-
from linkedin_mcp_server.config import get_config
19-
from linkedin_mcp_server.config.providers import clear_credentials_from_keyring
20-
from linkedin_mcp_server.config.secrets import get_credentials
2113
from linkedin_scraper.exceptions import (
2214
CaptchaRequiredError,
2315
InvalidCredentialsError,
@@ -26,6 +18,14 @@
2618
SecurityChallengeError,
2719
TwoFactorAuthError,
2820
)
21+
from selenium import webdriver
22+
from selenium.common.exceptions import WebDriverException
23+
from selenium.webdriver.chrome.options import Options
24+
from selenium.webdriver.chrome.service import Service
25+
26+
from linkedin_mcp_server.config import get_config
27+
from linkedin_mcp_server.config.providers import clear_credentials_from_keyring
28+
from linkedin_mcp_server.config.secrets import get_credentials
2929
from linkedin_mcp_server.exceptions import (
3030
CredentialsNotFoundError,
3131
DriverInitializationError,
@@ -133,9 +133,6 @@ def get_or_create_driver() -> Optional[webdriver.Chrome]:
133133
raise WebDriverException(error_msg)
134134

135135

136-
# Remove this function - linkedin-scraper now handles all error detection
137-
138-
139136
def login_to_linkedin(driver: webdriver.Chrome) -> bool:
140137
"""
141138
Log in to LinkedIn using stored or provided credentials.

linkedin_mcp_server/error_handler.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
eliminating code duplication and ensuring consistent error responses.
66
"""
77

8+
import logging
89
from typing import Any, Dict, List
910

1011
from linkedin_scraper.exceptions import (
@@ -135,8 +136,16 @@ def convert_exception_to_response(
135136
return {"error": "linkedin_error", "message": str(exception)}
136137

137138
else:
138-
# Generic error handling
139-
print(f"❌ Error in {context}: {exception}")
139+
# Generic error handling with structured logging
140+
logger = logging.getLogger(__name__)
141+
logger.error(
142+
f"Error in {context}: {exception}",
143+
extra={
144+
"context": context,
145+
"exception_type": type(exception).__name__,
146+
"exception_message": str(exception),
147+
},
148+
)
140149
return {
141150
"error": "unknown_error",
142151
"message": f"Failed to execute {context}: {str(exception)}",

0 commit comments

Comments
 (0)