Skip to content

Commit

Permalink
Standard GET responses should check for undefined and null
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisrohr committed Oct 2, 2024
1 parent c0061e1 commit 34ddad3
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/express/kiwi-standard-responses-express.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@ const standardGetResponseWithIdentifier = (
identifier: unknown,
entity: unknown,
) => {
if (entity !== undefined) {
res.status(200).json(entity);
if (entity === undefined || entity === null) {
standardNotFoundResponse(
res,
`Object with ${identifierField} ${identifier} not found`,
identifierField,
identifier,
);
return;
}

standardNotFoundResponse(
res,
`Object with ${identifierField} ${identifier} not found`,
identifierField,
identifier,
);
res.status(200).json(entity);
return;
};

/**
Expand All @@ -43,12 +44,13 @@ const standardGetResponseWithMessage = (
entity: unknown,
notFoundMessage: string,
) => {
if (entity !== undefined) {
res.status(200).json(entity);
if (entity === undefined || entity === null) {
standardNotFoundResponse(res, notFoundMessage);
return;
}

standardNotFoundResponse(res, notFoundMessage);
res.status(200).json(entity);
return;
};

/**
Expand Down

0 comments on commit 34ddad3

Please sign in to comment.