Skip to content

Commit 6c663a7

Browse files
committed
fix: return 404 if user not found instead of malformed request error
1 parent 6c00f79 commit 6c663a7

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

server/src/user/user.service.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,23 +146,21 @@ export class UserService {
146146

147147
if (email) {
148148
user = await this.findByEmail(email);
149-
}
150-
151-
if (id) {
149+
} else if (id) {
152150
user = await this.findByID(id);
153-
}
154-
155-
if (username) {
151+
} else if (username) {
156152
user = await this.findByUsername(username);
157-
}
158-
159-
if (!user) {
153+
} else {
160154
throw new HttpException(
161155
'You must provide an email, ID or username',
162156
HttpStatus.BAD_REQUEST,
163157
);
164158
}
165159

160+
if (!user) {
161+
throw new HttpException('User not found', HttpStatus.NOT_FOUND);
162+
}
163+
166164
return UserProfileViewDto.fromUserDocument(user);
167165
}
168166

0 commit comments

Comments
 (0)