Skip to content

Commit

Permalink
fix: handle parsing errors causing the app to crash (#974)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmbronco authored Sep 25, 2024
1 parent 5419dc5 commit bcd8189
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/tender-boxes-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'backend': patch
---

Handle parsing errors causing the app to crash
18 changes: 11 additions & 7 deletions apps/api/middleware/lowerCaseMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,19 @@ const casedQueryParams = (query: string): string => {
export async function lowerCaseMiddleware(req: Request, res: Response, next: NextFunction) {
json()(req, res, (err) => {
if (req.method === 'POST' && req.is('application/json') && req.body) {
const { query, variables } = req.body;
try {
const { query, variables } = req.body;

if (variables) {
convertLetterCase(variables);
}
if (variables) {
convertLetterCase(variables);
}

if (query) {
// Replacing the original query with the lowercase one
req.body.query = casedQueryParams(query);
if (query) {
// Replacing the original query with the lowercase one
req.body.query = casedQueryParams(query);
}
} catch (error) {
return next(error);
}
}

Expand Down

0 comments on commit bcd8189

Please sign in to comment.