Pass the relay's work_email_required error through the viewer server

Classify the relay's 400 work_email_required separately from a malformed
address so the browser can show the "use your work email" message.
This commit is contained in:
Jonathan Singer
2026-07-20 13:31:19 -04:00
parent d73f319be5
commit 9d4033d950
2 changed files with 6 additions and 1 deletions
+5 -1
View File
@@ -123,12 +123,16 @@ def _parse_body(raw: bytes) -> dict[str, Any]:
def otp_start(email: str) -> None:
"""Ask the relay to email a verification code. Raises RelayError on failure."""
status, _ = _post_json("/api/oss/otp/start", {"email": email}, timeout=_OTP_TIMEOUT)
status, data = _post_json("/api/oss/otp/start", {"email": email}, timeout=_OTP_TIMEOUT)
if status == 200:
return
if status == 429:
raise RelayError("rate_limited")
if status == 400:
# The relay uses 400 both for a malformed address and, separately, to
# reject a free/personal email domain (it wants a work email).
if data.get("error") == "work_email_required":
raise RelayError("work_email_required")
raise RelayError("invalid_email")
raise RelayError("unavailable")
+1
View File
@@ -284,6 +284,7 @@ def _make_handler(state: _ViewerState) -> type[BaseHTTPRequestHandler]:
status_by_code = {
"rate_limited": HTTPStatus.TOO_MANY_REQUESTS,
"invalid_email": HTTPStatus.BAD_REQUEST,
"work_email_required": HTTPStatus.BAD_REQUEST,
"invalid_code": HTTPStatus.FORBIDDEN,
"reverify": HTTPStatus.UNAUTHORIZED,
"forbidden": HTTPStatus.FORBIDDEN,