Skip to content

Commit

Permalink
✨ refactor with error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jiisanda committed Nov 3, 2023
1 parent 96d554e commit 31c1b76
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions db/repositories/documents/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,26 @@ async def notify(self, user: TokenData, receivers: List[str], filename: str, aut

for receiver in receivers:

receiver_details = (await auth_repo.get_user(field="email", detail=receiver)).__dict__

notify_entry = Notify(
receiver_id=receiver_details["id"],
message=f"{user.username} shared {filename} with you! Access the shared file via mail...",
status=NotifyEnum.unread
)

receiver_details = await auth_repo.get_user(field="email", detail=receiver)
try:
self.session.add(notify_entry)
await self.session.commit()
await self.session.refresh(notify_entry)
notify_entry = Notify(
receiver_id=receiver_details.__dict__["id"],
message=f"{user.username} shared {filename} with you! Access the shared file via mail...",
status=NotifyEnum.unread
)

try:
self.session.add(notify_entry)
await self.session.commit()
await self.session.refresh(notify_entry)
except Exception as e:
raise HTTP_500(
msg="Error notifying the user, but the mail has been sent successfully."
) from e
except Exception as e:
raise HTTP_500() from e
raise HTTP_404(
msg="The user does not exists, make sure the user has an account on docflow..."
)

async def get_notification_by_id(self, n_id: UUID, user: TokenData) -> Notification:
"""
Expand Down

0 comments on commit 31c1b76

Please sign in to comment.