Skip to content

Commit f1c8f22

Browse files
authored
fix: capture query errors explicitely (#100)
1 parent 3d555e5 commit f1c8f22

1 file changed

Lines changed: 28 additions & 12 deletions

File tree

src/utils/query.ts

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import type { ZodSchema } from 'zod';
33
import { zodToJsonSchema } from 'zod-to-json-schema';
44
import type { AIModel, CloudRegion } from './types';
55
import { getCloudUrlFromRegion } from './urls';
6+
import { analytics } from './analytics';
7+
import { AxiosError } from 'axios';
68

79
export const query = async <S>({
810
message,
@@ -19,19 +21,33 @@ export const query = async <S>({
1921
}): Promise<S> => {
2022
const jsonSchema = zodToJsonSchema(schema, 'schema').definitions;
2123

22-
const response = await axios.post<{ data: unknown }>(
23-
`${getCloudUrlFromRegion(region)}/api/wizard/query`,
24-
{
25-
message,
26-
model,
27-
json_schema: { ...jsonSchema, name: 'schema', strict: true },
28-
},
29-
{
30-
headers: {
31-
'X-PostHog-Wizard-Hash': wizardHash,
24+
const response = await axios
25+
.post<{ data: unknown }>(
26+
`${getCloudUrlFromRegion(region)}/api/wizard/query`,
27+
{
28+
message,
29+
model,
30+
json_schema: { ...jsonSchema, name: 'schema', strict: true },
3231
},
33-
},
34-
);
32+
{
33+
headers: {
34+
'X-PostHog-Wizard-Hash': wizardHash,
35+
},
36+
},
37+
)
38+
.catch((error) => {
39+
if (error instanceof AxiosError) {
40+
analytics.captureException(error, {
41+
response_status_code: error.response?.status,
42+
message,
43+
model,
44+
json_schema: jsonSchema,
45+
type: 'wizard_query_error',
46+
});
47+
}
48+
49+
throw error;
50+
});
3551

3652
const validation = schema.safeParse(response.data.data);
3753

0 commit comments

Comments
 (0)