Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Commit

Permalink
feat(user): add entity not found exception
Browse files Browse the repository at this point in the history
  • Loading branch information
igorkamyshev committed Jan 29, 2019
1 parent 15ca954 commit dbabd81
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion back/src/user/domain/UserRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { InjectRepository } from '@nestjs/typeorm'
import { Option } from 'tsoption'
import { Repository } from 'typeorm'

import { EntityNotFoundException } from '@back/utils/domain/EntityNotFoundException'

import { User } from './User.entity'

@Injectable()
Expand All @@ -16,7 +18,9 @@ class UserRepo {
const user = await this.userRepo.findOne(login)

if (!user) {
// TODO: throw error
throw new EntityNotFoundException(User.name, {
login,
})
}

return user
Expand Down
8 changes: 8 additions & 0 deletions back/src/utils/domain/EntityNotFoundException.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export class EntityNotFoundException extends Error {
public constructor(
public readonly enitityName: string,
public readonly query: object,
) {
super(`${enitityName} not found by query: ${query}`)
}
}

0 comments on commit dbabd81

Please sign in to comment.