Hello!
I'm having trouble understanding the purpose of ChainedError in the src/connections/AbstractConnection.ts file, specifically in the transaction method.
In my situation, my services can throw various errors within a transaction, including validation errors, and I would like to get the original errors immediately. However, I'm getting something like this:
ChainedError: [object Object]
at ...
Caused By: undefined
Transaction source: Error: Transaction executed at
at DBConnection.transaction
...
[cause]: ValidationErrors { fields: Map(1) { 'code' => [ { message: 'Invalid coupon code' } ] } }
I had to override the transaction method in DBConnection to avoid adding try-catch blocks everywhere:
class DBConnection extends MySqlConnection<'Connection'> {
allowEmptyString = true;
protected compatibilityMode = true;
transaction<P extends Promise<any>[]>(fn: () => [...P]): Promise<UnwrapPromiseTuple<P>>;
transaction<T>(fn: () => Promise<T>): Promise<T>;
async transaction(fn: any): Promise<any> {
try {
return await super.transaction(fn);
} catch (error) {
if (error.cause) {
throw error.cause;
}
throw error;
}
}
}
My question is, what is the purpose of ChainedError, and is it possible to work without it?
Is there any specific reason for using ChainedError in this context, or can it be removed (can avoid wrapping errors and simply return them as they are)?
Hello!
I'm having trouble understanding the purpose of
ChainedErrorin the src/connections/AbstractConnection.ts file, specifically in thetransactionmethod.In my situation, my services can throw various errors within a transaction, including validation errors, and I would like to get the original errors immediately. However, I'm getting something like this:
I had to override the
transactionmethod inDBConnectionto avoid adding try-catch blocks everywhere:My question is, what is the purpose of ChainedError, and is it possible to work without it?
Is there any specific reason for using ChainedError in this context, or can it be removed (can avoid wrapping errors and simply return them as they are)?