Spaces:
Runtime error
Runtime error
File size: 1,155 Bytes
b3b8f74 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | export class PostgresError extends Error {
constructor(x) {
super(x.message)
this.name = this.constructor.name
Object.assign(this, x)
}
}
export const Errors = {
connection,
postgres,
generic,
notSupported
}
function connection(x, options, socket) {
const { host, port } = socket || options
const error = Object.assign(
new Error(('write ' + x + ' ' + (options.path || (host + ':' + port)))),
{
code: x,
errno: x,
address: options.path || host
}, options.path ? {} : { port: port }
)
Error.captureStackTrace(error, connection)
return error
}
function postgres(x) {
const error = new PostgresError(x)
Error.captureStackTrace(error, postgres)
return error
}
function generic(code, message) {
const error = Object.assign(new Error(code + ': ' + message), { code })
Error.captureStackTrace(error, generic)
return error
}
/* c8 ignore next 10 */
function notSupported(x) {
const error = Object.assign(
new Error(x + ' (B) is not supported'),
{
code: 'MESSAGE_NOT_SUPPORTED',
name: x
}
)
Error.captureStackTrace(error, notSupported)
return error
}
|