diff --git a/src/api/private/auth/auth.controller.ts b/src/api/private/auth/auth.controller.ts index 8ddd4b6b3..23b35ac5d 100644 --- a/src/api/private/auth/auth.controller.ts +++ b/src/api/private/auth/auth.controller.ts @@ -75,25 +75,15 @@ export class AuthController { @RequestUser() user: User, @Body() changePasswordDto: UpdatePasswordDto, ): Promise { - try { - await this.identityService.checkLocalPassword( - user, - changePasswordDto.currentPassword, - ); - await this.identityService.updateLocalPassword( - user, - changePasswordDto.newPassword, - ); - return; - } catch (e) { - if (e instanceof InvalidCredentialsError) { - throw new UnauthorizedException('Password is not correct'); - } - if (e instanceof NoLocalIdentityError) { - throw new BadRequestException('User has no local identity.'); - } - throw e; - } + await this.identityService.checkLocalPassword( + user, + changePasswordDto.currentPassword, + ); + await this.identityService.updateLocalPassword( + user, + changePasswordDto.newPassword, + ); + return; } @UseGuards(LoginEnabledGuard, LocalAuthGuard) diff --git a/src/identity/identity.service.ts b/src/identity/identity.service.ts index 044eb86bf..dbb9c02ae 100644 --- a/src/identity/identity.service.ts +++ b/src/identity/identity.service.ts @@ -85,14 +85,14 @@ export class IdentityService { `The user with the username ${user.username} does not have a internal identity.`, 'checkLocalPassword', ); - throw new NoLocalIdentityError(); + throw new NoLocalIdentityError('This user has no internal identity.'); } if (!(await checkPassword(password, internalIdentity.passwordHash ?? ''))) { this.logger.debug( `Password check for ${user.username} did not succeed.`, 'checkLocalPassword', ); - throw new InvalidCredentialsError(); + throw new InvalidCredentialsError('Password is not correct'); } } }