Currently, I am experimenting with TypeScript and a library called TypeORM while constructing custom repositories for my models.
Within my models, specifically the Buyer
model, there is a corresponding BuyerRepository
featuring a method named createAndSave
.
If the goal is for this method to either return a successful Buyer
or an Error('some reason')
if an issue arises, would it be appropriate to utilize
throw new Error('buyer already exists')
?
I am aiming for functionality akin to Go's approach:
res, err := buyerRepo.createAndSave(buyer)