Skip to content

Commit 6670ead

Browse files
committed
return 404 in api when not project found
1 parent 23184e4 commit 6670ead

File tree

4 files changed

+6
-35
lines changed

4 files changed

+6
-35
lines changed

api/src/app/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { ProjectController } from "src/project/controller";
1818
import { SQLiteService } from "src/sqlite/service";
1919
import Container from "typedi";
2020

21-
import { ErrorMiddleware } from "./middlewares/error";
2221
import { LoggerMiddleware } from "./middlewares/logger";
2322
import { RobotsController } from "./middlewares/robots";
2423
import { SecurityMiddleware } from "./middlewares/security";
@@ -45,8 +44,7 @@ const routingControllersOptions: RoutingControllersOptions = {
4544
ContributorController,
4645
RobotsController,
4746
],
48-
middlewares: [SecurityMiddleware, ErrorMiddleware, LoggerMiddleware],
49-
defaultErrorHandler: false,
47+
middlewares: [SecurityMiddleware, LoggerMiddleware],
5048
cors: Container.get(SecurityMiddleware).cors(),
5149
};
5250
const app: Application = createExpressServer(routingControllersOptions);

api/src/app/middlewares/error.ts

Lines changed: 0 additions & 30 deletions
This file was deleted.

api/src/project/controller.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Controller, Get, Param } from "routing-controllers";
1+
import { Controller, Get, NotFoundError, Param } from "routing-controllers";
22
import { Service } from "typedi";
33

44
import { ProjectRepository } from "./repository";
@@ -49,6 +49,8 @@ export class ProjectController {
4949
public async getProjectName(@Param("id") id: number): Promise<GetProjectNameResponse> {
5050
const project = await this.projectRepository.findName(id);
5151

52+
if (!project) throw new NotFoundError("Project not found");
53+
5254
return { project };
5355
}
5456
}

api/src/project/repository.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export class ProjectRepository {
1313
constructor(private readonly sqliteService: SQLiteService) {}
1414

1515
public async findName(projectId: number) {
16-
// @TODO-ZM: handle 404
1716
const statement = sql`
1817
SELECT
1918
name
@@ -23,6 +22,8 @@ export class ProjectRepository {
2322
id = ${projectId}
2423
`;
2524
const raw = this.sqliteService.db.get(statement);
25+
if (!raw) return null;
26+
2627
const unStringifiedRaw = unStringifyDeep(raw);
2728
const camelCased = camelCaseObject(unStringifiedRaw);
2829
return camelCased;

0 commit comments

Comments
 (0)