-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.ts
More file actions
24 lines (22 loc) · 972 Bytes
/
Copy patherrors.ts
File metadata and controls
24 lines (22 loc) · 972 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { AuthenticationError, BadRequestError, Interfaze, InterfazeError, RateLimitError } from "interfaze";
const interfaze = new Interfaze();
try {
const res = await interfaze.chat.completions.create({
messages: [{ role: "user", content: "Hello!" }],
});
console.log(res.choices[0]?.message.content);
} catch (err) {
// `InterfazeError` is client-side (missing key, invalid guard code, stream misuse).
// Everything else is an APIError subclass carrying `status` and `code`.
if (err instanceof RateLimitError) {
console.error("rate limited (429) - back off and retry:", err.message);
} else if (err instanceof AuthenticationError) {
console.error("auth failed (401) - check INTERFAZE_API_KEY:", err.message);
} else if (err instanceof BadRequestError) {
console.error("bad request (400):", err.message);
} else if (err instanceof InterfazeError) {
console.error("client-side error:", err.message);
} else {
throw err;
}
}