For example, when using getTaskById method, the id selected could not match any of the tasks. NestJS allow us to handle this error by just simply adding the following:
getTaskById(id: string): Task {
const found = this.tasks.find(task => task.id === id);
if (!found) {
throw new NotFoundException(`Task with ID "${id}" not found`);
}
return found;
}