|
@@ -1,19 +1,27 @@
|
|
|
import axios from "axios";
|
|
import axios from "axios";
|
|
|
import type { NextApiHandler } from "next";
|
|
import type { NextApiHandler } from "next";
|
|
|
-import { errorHandler } from "../../utils/apiErrorHandler";
|
|
|
|
|
|
|
|
|
|
const signUpHandler: NextApiHandler = async (req, res) => {
|
|
const signUpHandler: NextApiHandler = async (req, res) => {
|
|
|
- if (req.body) {
|
|
|
|
|
- try {
|
|
|
|
|
- const response = await axios.post(
|
|
|
|
|
- `${process.env.PRISMA_API}/register`,
|
|
|
|
|
- req.body,
|
|
|
|
|
- { headers: { "Content-Type": "application/json" } }
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ const response = await axios.post(
|
|
|
|
|
+ `${process.env.PRISMA_API}/register`,
|
|
|
|
|
+ req.body,
|
|
|
|
|
+ { headers: { "Content-Type": "application/json" } }
|
|
|
|
|
+ );
|
|
|
|
|
+ res.status(response.status).json(response.data);
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ if (axios.isAxiosError(e)) {
|
|
|
|
|
+ res.status(e.response?.status || 500).json(e.response?.data);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ console.error(
|
|
|
|
|
+ `Error while trying to register: ${JSON.stringify(req.body, null, 2)}`
|
|
|
);
|
|
);
|
|
|
- res.status(200).json(response.data);
|
|
|
|
|
- } catch (error) {
|
|
|
|
|
- const { status, message } = errorHandler(error);
|
|
|
|
|
- res.status(status).json({ message });
|
|
|
|
|
|
|
+ res
|
|
|
|
|
+ .status(500)
|
|
|
|
|
+ .json({
|
|
|
|
|
+ message:
|
|
|
|
|
+ "There was an error processing the request, please try again.",
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|