Change error types in checkLocalPassword and updateLocalPassword to InvalidCredentialsError and NoLocalIdentityError

Signed-off-by: Yannick Bungers <git@innay.de>
This commit is contained in:
Yannick Bungers 2022-01-06 21:59:46 +01:00 committed by David Mehren
parent f39315ea7b
commit b562a5dac7
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
4 changed files with 38 additions and 15 deletions

View file

@ -17,7 +17,11 @@ import {
} from '@nestjs/common';
import { Session } from 'express-session';
import { AlreadyInDBError, NotInDBError } from '../../../errors/errors';
import {
AlreadyInDBError,
InvalidCredentialsError,
NoLocalIdentityError,
} from '../../../errors/errors';
import { IdentityService } from '../../../identity/identity.service';
import { LocalAuthGuard } from '../../../identity/local/local.strategy';
import { LoginDto } from '../../../identity/local/login.dto';
@ -80,10 +84,11 @@ export class AuthController {
);
return;
} catch (e) {
if (e instanceof NotInDBError) {
throw new UnauthorizedException(
'Verifying your identity with the current password did not work.',
);
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;
}