aboutsummaryrefslogtreecommitdiff
path: root/src/index.ts
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2021-06-02 23:11:00 -0500
committermat <github@matdoes.dev>2021-06-02 23:11:00 -0500
commit2eb6d7658ac0afa45fd8258a68c7640e4c9e372e (patch)
treefb874bbe80994abfe403d15238635ba2bbdfcc2b /src/index.ts
parentb479701eada6dc2beb8018e768e109b687a9fc1d (diff)
downloadskyblock-api-2eb6d7658ac0afa45fd8258a68c7640e4c9e372e.tar.gz
skyblock-api-2eb6d7658ac0afa45fd8258a68c7640e4c9e372e.tar.bz2
skyblock-api-2eb6d7658ac0afa45fd8258a68c7640e4c9e372e.zip
actually 404 when something isn't found
Diffstat (limited to 'src/index.ts')
-rw-r--r--src/index.ts26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/index.ts b/src/index.ts
index 489ef52..4f4ad00 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -46,16 +46,18 @@ app.get('/', async(req, res) => {
app.get('/player/:user', async(req, res) => {
try {
- res.json(
- await fetchUser(
- { user: req.params.user },
- [req.query.basic as string === 'true' ? undefined : 'profiles', 'player'],
- req.query.customization as string === 'true'
- )
+ const user = await fetchUser(
+ { user: req.params.user },
+ [req.query.basic as string === 'true' ? undefined : 'profiles', 'player'],
+ req.query.customization as string === 'true'
)
+ if (user)
+ res.json(user)
+ else
+ res.status(404).json({ error: true })
} catch (err) {
console.error(err)
- res.json({ 'error': true })
+ res.json({ error: true })
}
})
@@ -72,12 +74,14 @@ app.get('/discord/:id', async(req, res) => {
app.get('/player/:user/:profile', async(req, res) => {
try {
- res.json(
- await fetchMemberProfile(req.params.user, req.params.profile, req.query.customization as string === 'true')
- )
+ const profile = await fetchMemberProfile(req.params.user, req.params.profile, req.query.customization as string === 'true')
+ if (profile)
+ res.json(profile)
+ else
+ res.status(404).json({ error: true })
} catch (err) {
console.error(err)
- res.json({ 'error': true })
+ res.json({ error: true })
}
})