NERDDISCO commited on
Commit
fa302b9
•
1 Parent(s): 67f2f95

fix: error handling

Browse files
Files changed (1) hide show
  1. src/pages/api/generate.ts +4 -1
src/pages/api/generate.ts CHANGED
@@ -3,6 +3,7 @@ import { NextApiRequest, NextApiResponse } from "next";
3
  import { AxiosError } from "axios";
4
  import process from "node:process";
5
  import { createClient } from "@/services/api/openai";
 
6
 
7
  export default async function handler(request: NextApiRequest, response: NextApiResponse) {
8
  switch (request.method) {
@@ -13,7 +14,9 @@ export default async function handler(request: NextApiRequest, response: NextApi
13
  const answer = await toOpenAI({ ...request.body, client });
14
  return response.status(200).json(answer);
15
  } catch (error) {
16
- return response.status((error as AxiosError).status ?? 500).json(error);
 
 
17
  }
18
  default:
19
  return response.status(405).json({});
 
3
  import { AxiosError } from "axios";
4
  import process from "node:process";
5
  import { createClient } from "@/services/api/openai";
6
+ import { CustomAxiosError } from "@/services/api/axios";
7
 
8
  export default async function handler(request: NextApiRequest, response: NextApiResponse) {
9
  switch (request.method) {
 
14
  const answer = await toOpenAI({ ...request.body, client });
15
  return response.status(200).json(answer);
16
  } catch (error) {
17
+ return response.status((error as AxiosError).status ?? 500).json({
18
+ message: (error as CustomAxiosError).data?.error?.message ?? "UNKNOWN",
19
+ });
20
  }
21
  default:
22
  return response.status(405).json({});