From 4d0fd81a91ef890ab71c9576a086dccfae350f02 Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 15 Jun 2019 15:26:00 -0400 Subject: [PATCH] Add error handling to getRSNFormat --- src/hiscores.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/hiscores.ts b/src/hiscores.ts index e5eea68..126f3c8 100644 --- a/src/hiscores.ts +++ b/src/hiscores.ts @@ -43,6 +43,7 @@ export async function getStats( } else if (!MODES.includes(mode)) { throw Error('Invalid game mode'); } + if (mode === 'full') { const mainRes = await axios(getStatsURL('main', rsn)); if (mainRes.status === 200) { @@ -187,6 +188,14 @@ export async function getActivityPage( } export async function getRSNFormat(rsn: string): Promise { + if (typeof rsn !== 'string') { + throw Error('RSN must be a string'); + } else if (!/^[a-zA-Z0-9 _]+$/.test(rsn)) { + throw Error('RSN contains invalid character'); + } else if (rsn.length > 12 || rsn.length < 1) { + throw Error('RSN must be between 1 and 12 characters'); + } + const url = getPlayerTableURL('main', rsn); try { const response = await axios(url);