diff --git a/api/src/controllers/users.ts b/api/src/controllers/users.ts index 2e0888141e..b3b7ce4eb1 100644 --- a/api/src/controllers/users.ts +++ b/api/src/controllers/users.ts @@ -58,11 +58,21 @@ router.get( if (!req.accountability?.user) { throw new InvalidCredentialsException(); } + const service = new UsersService({ accountability: req.accountability }); - const item = await service.readByKey(req.accountability.user, req.sanitizedQuery); + try { + const item = await service.readByKey(req.accountability.user, req.sanitizedQuery); + res.locals.payload = { data: item || null }; + } catch (error) { + if (error instanceof ForbiddenException) { + res.locals.payload = { data: { id: req.accountability.user } }; + return next(); + } + + throw error; + } - res.locals.payload = { data: item || null }; return next(); }), respond