|
11 | 11 | import logging |
12 | 12 |
|
13 | 13 | from aiohttp import web |
14 | | -from models_library.error_codes import create_error_code |
15 | 14 | from models_library.users import UserID |
16 | 15 | from pydantic import BaseModel, Field |
17 | | -from servicelib.logging_utils import LogExtra, get_log_record_extra, log_decorator |
| 16 | +from servicelib.logging_utils import log_decorator |
18 | 17 | from servicelib.utils_secrets import generate_passcode |
19 | 18 | from settings_library.twilio import TwilioSettings |
20 | 19 | from twilio.base.exceptions import TwilioException # type: ignore[import-untyped] |
@@ -132,15 +131,11 @@ def _sender(): |
132 | 131 | await asyncio.get_event_loop().run_in_executor(executor=None, func=_sender) |
133 | 132 |
|
134 | 133 | except TwilioException as exc: |
135 | | - error_code = create_error_code(exc) |
136 | | - log_extra: LogExtra = get_log_record_extra(user_id=user_id) or {} |
137 | | - log.exception( |
138 | | - "Failed while setting up 2FA code and sending SMS to %s [%s]", |
139 | | - mask_phone_number(phone_number), |
140 | | - f"{error_code}", |
141 | | - extra={"error_code": error_code, **log_extra}, |
142 | | - ) |
143 | | - raise SendingVerificationSmsError(reason=exc) from exc |
| 134 | + raise SendingVerificationSmsError( |
| 135 | + reason=f"Could not send SMS to {mask_phone_number(phone_number)}", |
| 136 | + user_id=user_id, |
| 137 | + twilio_error=exc, |
| 138 | + ) from exc |
144 | 139 |
|
145 | 140 |
|
146 | 141 | # |
@@ -177,16 +172,13 @@ async def send_email_code( |
177 | 172 | "product": product, |
178 | 173 | }, |
179 | 174 | ) |
180 | | - except TwilioException as exc: |
181 | | - error_code = create_error_code(exc) |
182 | | - log_extra: LogExtra = get_log_record_extra(user_id=user_id) or {} |
183 | | - log.exception( |
184 | | - "Failed while setting up 2FA code and sending Email to %s [%s]", |
185 | | - user_email, |
186 | | - f"{error_code}", |
187 | | - extra={"error_code": error_code, **log_extra}, |
188 | | - ) |
189 | | - raise SendingVerificationEmailError(reason=exc) from exc |
| 175 | + except Exception as exc: |
| 176 | + raise SendingVerificationEmailError( |
| 177 | + reason=f"Could not send email to {user_email}", |
| 178 | + user_id=user_id, |
| 179 | + user_email=user_email, |
| 180 | + email_error=exc, |
| 181 | + ) from exc |
190 | 182 |
|
191 | 183 |
|
192 | 184 | # |
|
0 commit comments