Skip to content

Commit

Permalink
Use json in 404 message
Browse files Browse the repository at this point in the history
  • Loading branch information
Timothy-Gonzalez committed Oct 23, 2024
1 parent 6da2288 commit add3ebb
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,22 @@ app.use("/docs/json", (_req, res) => res.json(getOpenAPISpec()));
app.use("/docs", swaggerUi.serveFiles(undefined, SWAGGER_UI_OPTIONS), swaggerUi.setup(undefined, SWAGGER_UI_OPTIONS));

// Ensure that API is running
const docsUrl = `${Config.ROOT_URL}/docs/`;
app.get("/", (_: Request, res: Response) => {
res.json({
ok: true,
info: "Welcome to HackIllinois' backend API!",
docs: `${Config.ROOT_URL}/docs/`,
docs: docsUrl,
});
});

// Throw an error if call is made to the wrong API endpoint
app.use("/", (_: Request, res: Response) => {
res.status(StatusCode.ClientErrorNotFound).end("API endpoint does not exist!");
res.status(StatusCode.ClientErrorNotFound).json({
error: "EndpointNotFound",
message: "This endpoint doesn't exist, see the docs!",
docs: docsUrl,
});
});

app.use(ErrorHandler);
Expand Down

0 comments on commit add3ebb

Please sign in to comment.