Currently errors are thrown as normal errors: throw new Error("Expected at least one row.");
It would be good if they had some typed metadata that could be used as follows:
import {from, isTypedError} from "@hediet/typed-sql";
try {
await db.exec(from(....));
} catch(e) {
if (!isTypedError(e)) throw e;
// e is fully typed here, and has meta data such as the sql error code / constraint name or the cause why typed-sql threw it.
}
implementation suggestion
typedErrorSymbol = Symbol("typedError");
export class TypedError extends Error {
[typedErrorSymbol]: true;
constructor(...) {}
}
export function isTypedError(e: any): e is TypedError {
return e && e[typedErrorSymbol];
}
Currently errors are thrown as normal errors:
throw new Error("Expected at least one row.");
It would be good if they had some typed metadata that could be used as follows:
implementation suggestion