I'm running NodeJS and pg-promise with a PostgreSQL backend. I've created my own TRIGGER which throws an exception in some cases. Things work fine at this end.
But with pg-promise I have trouble catching the error's name.
Using this code:
...
.catch(function(err) {
console.log(err);
});
I'm getting the following output:
[ { success: false,
result:
{ [error: vote_limit_exceeded]
name: 'error',
length: 80,
severity: 'ERROR',
code: 'P0001',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'pl_exec.c',
line: '3068',
routine: 'exec_stmt_raise' } } ]
I can see the name 'vote_limit_exceeded' in the context, but how do I return as a text string?
I've tried getting "close" with:
console.log(err[0].result);
But I'm not able to get the 'vote_limit_exceeded' isolated.