1- const NATIVE_NITRO_SQLITE_EXCEPTION_PREFIX = '[NitroSQLiteException] ' as const
21const NITRO_SQLITE_ERROR_NAME = 'NitroSQLiteError' as const
3- const getNitroSQLiteErrorPrefix = ( isNativeNitroSQLiteException : boolean ) =>
4- isNativeNitroSQLiteException ? '[NitroSQLite (Native/C++)]' : '[NitroSQLite] '
5-
6- type NitroSQLiteErrorOptions = ErrorOptions & {
7- isNativeNitroSQLiteException ?: boolean
8- }
92
103/**
114 * Custom error class for NitroSQLite operations
125 * Extends the native Error class with proper prototype chain and error handling
136 */
147export default class NitroSQLiteError extends Error {
15- constructor ( message : string , options ?: NitroSQLiteErrorOptions ) {
16- const { isNativeNitroSQLiteException = false , ...restOptions } =
17- options ?? { }
18-
19- super ( message , restOptions )
8+ constructor ( message : string , options ?: ErrorOptions ) {
9+ super ( message , options )
2010 this . name = NITRO_SQLITE_ERROR_NAME
21- this . message =
22- getNitroSQLiteErrorPrefix ( isNativeNitroSQLiteException ) + message
2311
2412 // Maintains proper prototype chain for instanceof checks
2513 Object . setPrototypeOf ( this , NitroSQLiteError . prototype )
@@ -35,16 +23,10 @@ export default class NitroSQLiteError extends Error {
3523 }
3624
3725 if ( error instanceof Error ) {
38- if ( error . message . includes ( NATIVE_NITRO_SQLITE_EXCEPTION_PREFIX ) ) {
39- return new NitroSQLiteError ( error . message , {
40- cause : error . cause ,
41- isNativeNitroSQLiteException : true ,
42- } )
43- }
44-
4526 const nitroSQLiteError = new NitroSQLiteError ( error . message , {
4627 cause : error . cause ,
4728 } )
29+
4830 // Preserve original stack trace if available
4931 if ( error . stack ) {
5032 nitroSQLiteError . stack = error . stack
@@ -53,11 +35,7 @@ export default class NitroSQLiteError extends Error {
5335 }
5436
5537 if ( typeof error === 'string' ) {
56- return new NitroSQLiteError ( error , {
57- isNativeNitroSQLiteException : error . includes (
58- NATIVE_NITRO_SQLITE_EXCEPTION_PREFIX ,
59- ) ,
60- } )
38+ return new NitroSQLiteError ( error )
6139 }
6240
6341 return new NitroSQLiteError ( 'Unknown error occurred' , {
0 commit comments