Skip to content

Commit

Permalink
fix: Graceful Error Handling (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChefKai authored Feb 3, 2021
1 parent 29ad401 commit 5d3cbf1
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions api/users/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NowRequest, NowResponse } from "@vercel/node";
import { isValidAddress, toChecksumAddress } from "ethereumjs-util";
import { toChecksumAddress } from "ethereumjs-util";
import { getModel } from "../../utils/mongo";

export default async (req: NowRequest, res: NowResponse): Promise<NowResponse | void> => {
Expand All @@ -9,7 +9,9 @@ export default async (req: NowRequest, res: NowResponse): Promise<NowResponse |

let { address } = req.query;
address = address as string;
if (isValidAddress(address)) {

// Sanity check for address; to avoid any SQL-like injections, ...
if (address.match(/^0x[0-9a-fA-F]{40}$/)) {
const userModel = await getModel("User");
const user = await userModel.findOne({ address: address.toLowerCase() }).lean();
if (!user) {
Expand Down

1 comment on commit 5d3cbf1

@vercel
Copy link

@vercel vercel bot commented on 5d3cbf1 Feb 3, 2021

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.