Skip to content

Commit 52f9486

Browse files
authored
fix: prevent server crash when cost is missing in response (#29)
1 parent d1083f7 commit 52f9486

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/main.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,8 @@ server.register(FastifyProxy, {
105105
return;
106106
}
107107

108-
// eslint-disable-next-line prefer-destructuring
109-
const cost = data.usage.cost;
110-
if (!cost) {
108+
const cost = data?.usage?.cost;
109+
if (!cost || typeof cost !== 'number') {
111110
request.log.error({ data }, 'Cannot read cost from response');
112111
return;
113112
}

0 commit comments

Comments
 (0)