Comparing version
@@ -58,24 +58,8 @@ import assert from 'assert'; | ||
catch (ex) { | ||
const qid = target.kmoreQueryId; | ||
assert(qid, 'kmoreQueryId should be set on QueryBuilder'); | ||
const trx = kmore.getTrxByKmoreQueryId(qid); | ||
if (trx) { // also processed on event `query-error` | ||
await kmore.finishTransaction(trx); | ||
} | ||
if (typeof reject === 'function') { | ||
// @ts-ignore | ||
return reject(ex); | ||
} | ||
if (ex instanceof Error) { | ||
throw ex; | ||
} | ||
else if (typeof ex === 'string') { | ||
throw new Error(ex); | ||
// return Promise.reject(new Error(ex)) | ||
} | ||
else { | ||
throw new Error('Kmore Error when executing then()', { | ||
cause: ex, | ||
}); | ||
} | ||
processEx({ | ||
ex, | ||
kmore, | ||
kmoreQueryId: target.kmoreQueryId, | ||
reject, | ||
}); | ||
} | ||
@@ -89,2 +73,27 @@ }; | ||
} | ||
function processEx(options) { | ||
const { ex, kmore, kmoreQueryId, reject } = options; | ||
const qid = kmoreQueryId; | ||
assert(qid, 'kmoreQueryId should be set on QueryBuilder'); | ||
const trx = kmore.getTrxByKmoreQueryId(qid); | ||
if (trx) { // also processed on event `query-error` | ||
void kmore.finishTransaction(trx).catch(console.error); | ||
} | ||
if (typeof reject === 'function') { | ||
// @ts-ignore | ||
return reject(ex); | ||
} | ||
if (ex instanceof Error) { | ||
throw ex; | ||
} | ||
else if (typeof ex === 'string') { | ||
throw new Error(ex); | ||
// return Promise.reject(new Error(ex)) | ||
} | ||
else { | ||
throw new Error('Kmore Error when executing then()', { | ||
cause: ex, | ||
}); | ||
} | ||
} | ||
//# sourceMappingURL=proxy.get.js.map |
{ | ||
"name": "kmore", | ||
"author": "waiting", | ||
"version": "46.0.0", | ||
"version": "46.0.1", | ||
"description": "A SQL query builder based on knex with powerful TypeScript type support", | ||
@@ -81,3 +81,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "539f51f9d0ee1d2883558ecf6ab0c47b13c2ad3a" | ||
"gitHead": "fbca9e7fc7067a1b880f9d76355029e2a626d2ba" | ||
} |
@@ -77,26 +77,8 @@ import assert from 'assert' | ||
catch (ex) { | ||
const qid = target.kmoreQueryId | ||
assert(qid, 'kmoreQueryId should be set on QueryBuilder') | ||
const trx = kmore.getTrxByKmoreQueryId(qid) | ||
if (trx) { // also processed on event `query-error` | ||
await kmore.finishTransaction(trx) | ||
} | ||
if (typeof reject === 'function') { | ||
// @ts-ignore | ||
return reject(ex) | ||
} | ||
if (ex instanceof Error) { | ||
throw ex | ||
} | ||
else if (typeof ex === 'string') { | ||
throw new Error(ex) | ||
// return Promise.reject(new Error(ex)) | ||
} | ||
else { | ||
throw new Error('Kmore Error when executing then()', { | ||
cause: ex, | ||
}) | ||
} | ||
processEx({ | ||
ex, | ||
kmore, | ||
kmoreQueryId: target.kmoreQueryId, | ||
reject, | ||
}) | ||
} | ||
@@ -112,1 +94,38 @@ } | ||
interface ProcessExOptions { | ||
kmore: KmoreBase | ||
kmoreQueryId: symbol | ||
reject: PromiseLike<unknown> | ((error: Error) => unknown) | undefined | ||
ex: unknown | ||
} | ||
function processEx(options: ProcessExOptions): never { | ||
const { ex, kmore, kmoreQueryId, reject } = options | ||
const qid = kmoreQueryId | ||
assert(qid, 'kmoreQueryId should be set on QueryBuilder') | ||
const trx = kmore.getTrxByKmoreQueryId(qid) | ||
if (trx) { // also processed on event `query-error` | ||
void kmore.finishTransaction(trx).catch(console.error) | ||
} | ||
if (typeof reject === 'function') { | ||
// @ts-ignore | ||
return reject(ex) | ||
} | ||
if (ex instanceof Error) { | ||
throw ex | ||
} | ||
else if (typeof ex === 'string') { | ||
throw new Error(ex) | ||
// return Promise.reject(new Error(ex)) | ||
} | ||
else { | ||
throw new Error('Kmore Error when executing then()', { | ||
cause: ex, | ||
}) | ||
} | ||
} | ||
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
244663
0.39%4154
0.8%