mirror of
https://github.com/Permissionless-Software-Foundation/x402-base-facilitator.git
synced 2026-09-21 16:52:01 -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',
|
router.get('/:id',
|
||||||
ensureUser,
|
ensureUser,
|
||||||
async (ctx) => {
|
async (ctx) => {
|
||||||
const user = await User.findById(ctx.params.id, '-password -salt')
|
try {
|
||||||
if (!user) {
|
const user = await User.findById(ctx.params.id, '-password -salt')
|
||||||
ctx.throw(404)
|
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