Skip to content

Commit

Permalink
fix backend-api sometimes throwing res.status is not a function (#3531)
Browse files Browse the repository at this point in the history
  • Loading branch information
wentokay authored Mar 31, 2023
1 parent f8a50e1 commit bbcdb3f
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions backend/native/backpack-api/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import cors from "cors";
import type { Request, Response } from "express";
import type { NextFunction, Request, Response } from "express";
import express from "express";
import { ZodError } from "zod";

Expand Down Expand Up @@ -65,16 +65,23 @@ app.get("/", (_req, res) => {
});
});

// @ts-ignore
app.use((err: any, _req: Request, res: Response) => {
if (err instanceof ZodError) {
return res.status(400).json({
message: zodErrorToString(err),
});
} else {
return res.status(500).json(err);
app.use(
(
err: any,
_req: Request,
res: Response,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_DO_NOT_REMOVE_THIS_PARAMETER_: NextFunction
) => {
if (err instanceof ZodError) {
return res.status(400).json({
message: zodErrorToString(err),
});
} else {
return res.status(500).json(err);
}
}
});
);

const port = process.env.PORT || 8080;
app.listen(port);
Expand Down

1 comment on commit bbcdb3f

@vercel
Copy link

@vercel vercel bot commented on bbcdb3f Mar 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.