[JS SDK] return a Error on failed database actions
I have a field in one of my database with a unique key.
Database.insert("INSERT INTO users (sip, domain) VALUES ('alice','example.com')")
.oncomplete(function(id) { log("created id=" + id); })
.onerror(function() {
log("some kind of database error happend, dont know details");
});
When a users tries to add a non-unique entry, the Database.onerror() is called.
But without the error.
At the stdout of the appservice i can see the error message and something that looks like the distinct error code 23505
PostgreSQLDatabase(00185d58,0017c1b8)::LastCommandFailed (23505):ERROR: duplicate key value violates unique constraint "domain" DETAIL: Key (domain)=(example.com) already exists.
I would like to receive this errortext and errorid to send the user a more detailed error-message with the actual reason than "error happend".
So i would like to have the error message and/or text to be includes as parameter.
Database.insert("INSERT INTO users (sip, domain) VALUES ('alice','example.com')")
.oncomplete(function(id) { log("created id=" + id); })
.onerror(function(errorid, errortext) {
if(errorid == 23505) {
log("sip or domain exists already");
} else {
log("unhandled db error: " + errortext);
}
});