hi guys, is there a way to return an error if a tr...
# help
l
hi guys, is there a way to return an error if a trigger is successful. I have a trigger that is working but it doesn't return an error in the frontend.
Copy code
create or replace function before_user_added()
returns trigger
language plpgsql
as $$
begin
  return case
    when (EXISTS(SELECT 1 from settings where user_id = new.user_id and role = 'investor'))
    then new
    else null
  end;
end $$;

create trigger before_auth_user_created
  before insert on investors_public
  for each row execute procedure before_user_added()
n
Hello @lanbau! This thread has been automatically created from your message in #843999948717555735 a few seconds ago. We have already mentioned the @User so that they can see your message and help you as soon as possible! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ``...`` menu) and select "Leave Thread" to unsubscribe from future updates. Want to change the title? Use the ``/title`` command! We have solved your problem? Click the button below to archive it.
s
We currently have a PR in the works that will allow you to throw exceptions in the trigger that will bubble back up to the auth api level so that you can catch it on the frontend.
n
lanbau (2022-05-22)