mirror of
https://github.com/Permissionless-Software-Foundation/bch-dex.git
synced 2026-09-21 16:52:00 -07:00
Throw 404 instead of 500 for cast error when fetching user
This commit is contained in:
@@ -17,12 +17,21 @@ router.get('/',
|
||||
router.get('/:id',
|
||||
ensureUser,
|
||||
async (ctx) => {
|
||||
const user = await User.findById(ctx.params.id, '-password -salt')
|
||||
if (!user) {
|
||||
ctx.throw(404)
|
||||
}
|
||||
try {
|
||||
const user = await User.findById(ctx.params.id, '-password -salt')
|
||||
if (!user) {
|
||||
ctx.throw(404)
|
||||
}
|
||||
|
||||
ctx.body = user
|
||||
ctx.body = user
|
||||
} catch (err) {
|
||||
|
||||
if (err === 404 || err.name === 'CastError') {
|
||||
ctx.throw(404)
|
||||
}
|
||||
|
||||
ctx.throw(500)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user