users.ts 558 B

12345678910111213141516171819
  1. import axios from "axios";
  2. import type { NextApiHandler } from "next";
  3. const usersHandler: NextApiHandler = async (req, res) => {
  4. try {
  5. const response = await axios.get(`${process.env.PRISMA_API}/users`);
  6. res.status(response.status).json(response.data);
  7. } catch (e) {
  8. if (axios.isAxiosError(e)) {
  9. res.status(e.response?.status || 500).json(e.response?.data);
  10. } else {
  11. res.status(500).json({
  12. message: "There was an error processing the request, please try again.",
  13. });
  14. }
  15. }
  16. };
  17. export default usersHandler;