HKUDS/DeepTutor · error · HTTPException

Avatar not found

Error message

Avatar not found

What it means

HTTP 404 raised by GET /avatar/{user_id} in deeptutor/api/routers/auth.py:729 when no avatar image file exists for the requested user id. Any authenticated user may view avatars, but the file must have been previously uploaded and not deleted; the response is the 404 rather than a FileResponse.

Solutions

  1. Fall back to the icon marker or a default avatar in the client on 404
  2. Verify the user_id is correct and corresponds to an uploaded avatar
  3. Re-upload if the avatar was removed
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at deeptutor/api/routers/auth.py:729 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of HKUDS/DeepTutor@3e82f13042 (2026-08-27). Data as JSON: /api/errors/6bbe210a559a7d93. Report an issue: GitHub.

Appendix: source

Thrown at deeptutor/api/routers/auth.py:729

    """Remove the current user's uploaded avatar image and reset the marker."""
    current = _require_profile_identity(payload)
    from deeptutor.multi_user.identity import delete_avatar_file

    if current.user_id and _USER_ID_RE.match(current.user_id):
        delete_avatar_file(current.user_id)
    set_avatar(current.username, "")
    return {"ok": True, "avatar": ""}


@router.get("/avatar/{user_id}")
async def get_avatar_image(
    user_id: str,
    _: TokenPayload | None = Depends(require_auth),
) -> FileResponse:
    """Serve a stored avatar image. Any authenticated user may view avatars
    (they appear in the admin table and next to the viewer's own profile)."""
    if not _USER_ID_RE.match(user_id):
        raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Avatar not found")

    from deeptutor.multi_user.identity import get_avatar_file

    target = get_avatar_file(user_id)
    if target is None:
        raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Avatar not found")

    media_type = _AVATAR_MEDIA_TYPES.get(target.suffix.lstrip("."), "application/octet-stream")
    headers = {
        # Private user content; the marker version in the URL handles busting.
        "Cache-Control": "private, max-age=86400",
        "X-Content-Type-Options": "nosniff",
        "Content-Disposition": "inline",
    }
    return FileResponse(path=str(target), media_type=media_type, headers=headers)


# ---------------------------------------------------------------------------

View on GitHub (pinned to 3e82f13042)