| 39 | const { logger } = deps; |
| 40 | |
| 41 | async function withLogging<T>( |
| 42 | path: string, |
| 43 | call: () => Promise<WireResult<T>>, |
| 44 | ): Promise<WireResult<T>> { |
| 45 | logger?.debug(`→ ${path}`); |
| 46 | const result = await call(); |
| 47 | if (result.ok) { |
| 48 | logger?.debug(`← ${path} ok`); |
| 49 | } else { |
| 50 | const e = result.error; |
| 51 | const raw = e.kind === "http" ? e.body : e.cause.message; |
| 52 | const clipped = raw.length > 200 ? raw.slice(0, 200) + "…" : raw; |
| 53 | const msg = e.kind === "http" ? `${e.status} ${clipped}` : clipped; |
| 54 | logger?.warn(`← ${path} error (${e.kind}): ${msg}`); |
| 55 | } |
| 56 | return result; |
| 57 | } |
| 58 | |
| 59 | return { |
| 60 | query: (path, input, schema) => { |