How to handle error when adding new row to Supabase

I'm trying to insert a new row containing a username when clicking a button. However, this action sometimes fails if the username is not unique. I can see an error like the following in the Chrome Dev console:

Error: PostgrestException(message: duplicate key value violates unique constraint "mailboxes_email_username_key", code: 23505, details: Key (email_username)=(asd) already exists.,

From the user's perspective, nothing is shown on the UI when that error happens.

How can I intercept such an error to display a meaningful message to the user?

8
13 replies