File size: 2,098 Bytes
7158b5e
f84ed9c
598fc2d
f84ed9c
598fc2d
7158b5e
 
 
598fc2d
7158b5e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
598fc2d
7158b5e
 
cc65c05
 
 
 
 
938a5c7
cc65c05
 
 
f6d47a2
 
 
 
 
 
 
 
 
cc65c05
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import logging
import httpx
from app.config.settings import NOTE_SERVICE_URL


class NoteServiceClient:
    async def create_audio_note(self, payload: dict):
        """Call the Note Service to create an audio note.

        This method catches HTTP errors and logs them instead of raising,
        to avoid making transcription endpoints return 500 when the
        Note Service is unavailable or returns 4xx/5xx.
        Returns parsed JSON on success or None on failure.
        """
        try:
            async with httpx.AsyncClient(timeout=30) as client:
                r = await client.post(
                    f"{NOTE_SERVICE_URL}/internal/notes/audio",
                    json=payload,
                )
                r.raise_for_status()
                return r.json()
        except httpx.HTTPStatusError as exc:
            status = getattr(exc.response, "status_code", "?")
            logging.warning(
                "NoteService returned HTTP %s for %s: %s",
                status,
                f"{NOTE_SERVICE_URL}/internal/notes/audio",
                exc,
            )
            return None
        except Exception as exc:  # network errors, timeouts, etc.
            logging.exception("Failed to call NoteService: %s", exc)
            return None

    async def save_transcript(self, payload: dict):
        # alias used elsewhere in the codebase
        return await self.create_audio_note(payload)
    
    async def update_note(self, note_id: str, payload: dict):
        async with httpx.AsyncClient(timeout=30) as client:
            r = await client.patch(
                f"{NOTE_SERVICE_URL}/notes/{note_id}",
                json=payload,
            )
            r.raise_for_status()
            return r.json()

    async def update_note_internal(self, note_id: str, payload: dict):
        async with httpx.AsyncClient(timeout=30) as client:
            r = await client.patch(
                f"{NOTE_SERVICE_URL}/internal/notes/{note_id}",
                json=payload,
            )
            r.raise_for_status()
            return r.json()