Skip to content

Commit 7fcdde3

Browse files
author
Elin Angelow
committed
fix: logger
1 parent 16f5205 commit 7fcdde3

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

lib/postgres/index.js

+24-14
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = async(
2424
{log = () => {}}
2525
) => {
2626
const {link: {gluePrefix = '.', schemas: sc} = {}} = config;
27-
const schemas = sc instanceof Array ? sc : [sc];
27+
const schemas = Array.isArray(sc) ? sc : [sc];
2828
const link = await connectionPool(log)(
2929
config.connection,
3030
{log}
@@ -117,13 +117,13 @@ module.exports = async(
117117
...methods,
118118
/**
119119
* Description
120-
* @param {Object} arguments
120+
* @param {Object} args
121121
* @param {number} txId
122122
* @returns {any}
123123
*/
124-
[jsName]: async(arguments = {}, txId) => {
124+
[jsName]: async(args = {}, txId) => {
125125
const dynArgs = args.input.map(({name}) => {
126-
if (arguments[name] === undefined) {
126+
if (args[name] === undefined) {
127127
if (oArgNames[name]!==undefined) {
128128
return oArgNames[name];
129129
}
@@ -132,7 +132,7 @@ module.exports = async(
132132
{fn: jsName, argument: name}
133133
);
134134
}
135-
return arguments[name];
135+
return args[name];
136136
});
137137
try {
138138
if (!txId) {
@@ -165,11 +165,16 @@ module.exports = async(
165165
* @returns {number}
166166
*/
167167
async txBegin() {
168-
const id = ++txId;
169-
const client = await link.connect();
170-
await client.query('BEGIN');
171-
txMap.set(id, client);
172-
return id;
168+
try {
169+
const id = ++txId;
170+
const client = await link.connect();
171+
await client.query('BEGIN');
172+
txMap.set(id, client);
173+
return id;
174+
} catch (e) {
175+
log('error', `TX Begin: id: ${id}`, e);
176+
throw e;
177+
}
173178
},
174179
/**
175180
* Description
@@ -178,10 +183,15 @@ module.exports = async(
178183
* @returns {void}
179184
*/
180185
async txEnd(id, action) {
181-
const client = txMap.get(id);
182-
await client.query(action);
183-
client.release();
184-
txMap.delete(id);
186+
try {
187+
const client = txMap.get(id);
188+
await client.query(action);
189+
client.release();
190+
txMap.delete(id);
191+
} catch (e) {
192+
log('error', `TX End: id: ${id}`, e);
193+
throw e;
194+
}
185195
}
186196
};
187197
};

0 commit comments

Comments
 (0)