Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
///
import * as pgPromise from 'pg-promise';
var result = new pgPromise.errors.QueryResultError();
var resultCheck = result instanceof pgPromise.errors.QueryResultError;
var query = new pgPromise.errors.QueryFileError();
var queryCheck = result instanceof pgPromise.errors.QueryFileError;
var line = query.error.position.line;
var ps = new pgPromise.errors.PreparedStatementError();
var queryCheck = result instanceof pgPromise.errors.PreparedStatementError;
var file = ps.error.file;
var qrec = pgPromise.errors.queryResultErrorCode;
var t = qrec.multiple;
var qf = new pgPromise.QueryFile('file');
var ps4 = new pgp.PreparedStatement({name: '', text: qf});
db.one(ps1);
db.one({
name: '',
text: ''
});
db.one({
name: '',
text: qf
});
var w = pgPromise.errors.PreparedStatementError;
// TODO: need to figure out how to export the type namespace;
//var test1 = ps1.parse();
///
import * as pgPromise from 'pg-promise';
var result = new pgPromise.errors.QueryResultError();
var resultCheck = result instanceof pgPromise.errors.QueryResultError;
var query = new pgPromise.errors.QueryFileError();
var queryCheck = result instanceof pgPromise.errors.QueryFileError;
var line = query.error.position.line;
var ps = new pgPromise.errors.PreparedStatementError();
var queryCheck = result instanceof pgPromise.errors.PreparedStatementError;
var file = ps.error.file;
var qrec = pgPromise.errors.queryResultErrorCode;
var t = qrec.multiple;
'use strict';
const _ = require('lodash');
const pgp = require('pg-promise');
const serverErrors = require('../../api-pls-utils/server-errors');
const queryErrorCode = pgp.errors.queryResultErrorCode;
const pgPromiseErrors = {
noData: serverErrors.notFound,
notEmpty: serverErrors.generic,
multiple: serverErrors.generic
};
// Pass in a `codeToFind` (a code sent back from pg-promise),
// and you'll get back an `errorDefinition` from `serverErrors`.
module.exports = function(codeToFind) {
var key = _.findKey(queryErrorCode, c => c === codeToFind);
return pgPromiseErrors[key];
};
module.exports = function({err, req, crudAction, query, selfLink}) {
const pls = req.pls;
var serverError;
// First, check to see if it's a pgp QueryResultError. If it
// is, we generate the appropriate server error.
if (err instanceof pgp.errors.QueryResultError) {
serverError = mapPgError(err.code);
}
// If it's not a pgp QueryResultError, we send over tbe generic server error.
else {
serverError = serverErrors.generic;
}
const dataToSend = {
errors: [serverError.body()]
};
if (selfLink) {
dataToSend.links = {
self: selfLink
};
function handleQueryError(err, res, resource, crudAction) {
var serverError;
// First, check to see if it's a pgp QueryResultError. If it
// is, we generate the appropriate server error.
if (err instanceof pgp.errors.QueryResultError) {
serverError = mapPgError(err.code);
}
// If it's not a pgp QueryResultError, we send over tbe generic server error.
else {
serverError = serverErrors.generic;
}
log.warn({
resourceName: resource.name,
err, crudAction
}, 'There was a query error with a CRUD request.');
res.status(serverError.code);
sendJson(res, {
errors: [serverError.body()]
});
it('should return the mapped error', () => {
const req = {};
const definition = {};
handleQueryError({
err: new pgp.errors.QueryResultError(0, {rows: {}}),
res: this.res,
req, definition
});
assert(this.res.status.calledOnce);
assert(this.res.status.calledWithExactly(2));
assert(this.sendJsonStub.calledOnce);
assert(this.sendJsonStub.calledWith(this.res, {
errors: [{
hungry: false
}]
}));
});
});
public async All(sql: string, parameters?: ISqlCommandParameters): Promise {
log.silly("All:", sql);
try {
return await this.db.many(Postgres.ParameterizeSql(sql), parameters);
} catch (ex) {
if (ex.code === pgPromise.errors.queryResultErrorCode.noData ) {
return [];
}
throw ex;
}
}