Skip to content

Commit

Permalink
feat: ✨ Control de errores
Browse files Browse the repository at this point in the history
Agregando control de errores en la implementacion de los casos de uso, para el registro del usuario
  • Loading branch information
HernanVelasquz committed Jun 16, 2023
1 parent 623ace3 commit 676a6f0
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/application/user/use-cases/register-user.use-case.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Injectable } from '@nestjs/common';
import { hash } from 'bcrypt';
import { from, Observable, switchMap } from 'rxjs';
import { from, Observable, switchMap, catchError, throwError } from 'rxjs';
import { UserEntity } from 'src/domain';
import { DuplicateUserException } from 'src/infrastructure';
import { DependencyUserAbstract } from './abstracts';

@Injectable()
Expand All @@ -13,6 +14,9 @@ export class RegisterUserUseCase extends DependencyUserAbstract {
const newUser = this.userFactoryService.createNewUser(createUserDto);
return from(this.dataServices.user.create(newUser));
}),
catchError(() =>
throwError(() => new DuplicateUserException(createUserDto.email)),
),
);
}
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ConflictException } from '@nestjs/common';

export class DuplicateUserException extends ConflictException {
constructor(email: string) {
super(
`El usuario con ${email} ya se encuentra registrado en la base de datos`,
);
}
}
1 change: 1 addition & 0 deletions src/infrastructure/exceptions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './duplicateUserException.exception';
1 change: 1 addition & 0 deletions src/infrastructure/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './data-service';
export * from './framework';
export * from './exceptions';

0 comments on commit 676a6f0

Please sign in to comment.