I would like to use standard ERROR message and code of PostgreSQL.
Right now, I can achieve my goal, but I would like to know the best way I can use.
Here is my current function in database.
CREATE OR REPLACE FUNCTION Dugong.Forget_Passwd_Add(
in_Username varchar(255),
in_randomURLs text
)
RETURNS void AS $$
BEGIN
IF (SELECT Dugong.Users_isExist(in_Username)) THEN
INSERT INTO dugong.Forget_Passwd (Username, randomURLs, used)
VALUES (in_Username, in_randomURLs, FALSE);
ELSE
RAISE EXCEPTION USING ERRCODE = '20000', MESSAGE = 'Username not found';
END IF;
END;
$$ LANGUAGE PLPGSQL;
My Node Express with pg module will use client.query(). client.query() has callback err and result.
With my example in here. I can use err.message and err.code to get error message and error code respectively.
Question :
I want my code be able to RAISE any error from database side not restrict only my specific error code.
How can I do that?