Class: DatabaseError
Defined in: src/types/errors.ts:377
Database operation error.
Remarks
Thrown when an internal database operation fails unexpectedly. This indicates a system-level error, not a user input problem.
Examples include:
- Query execution failures (unexpected null results)
- Connection failures (not covered by connection retry logic)
- Transaction commit/rollback failures
- Constraint violations at the database level
- Index corruption or unavailability
HTTP mapping: 500 Internal Server Error
Example
const record = result.records[0];
if (!record) {
throw new DatabaseError(
'CREATE',
'Failed to create field: no record returned from database'
);
}
Extends
Constructors
new DatabaseError()
new DatabaseError(
operation,message,cause?):DatabaseError
Defined in: src/types/errors.ts:394
Creates a new DatabaseError.
Parameters
operation
string
Type of operation (e.g., 'CREATE', 'UPDATE')
message
string
Description of the database failure
cause?
Error
Original database error (if available)
Returns
Overrides
Properties
cause?
readonlyoptionalcause:Error
Defined in: src/types/errors.ts:71
Original error that caused this error (if any).
Remarks
Error chaining allows tracking the full error context through multiple layers of the application. Useful for debugging complex error scenarios.
Example
try {
await fetchData();
} catch (err) {
throw new ValidationError('Failed to validate data', 'field', 'required', err as Error);
}
Inherited from
code
readonlycode:"DATABASE_ERROR"='DATABASE_ERROR'
Defined in: src/types/errors.ts:378
Machine-readable error code.
Remarks
Error codes are unique identifiers for error types, enabling programmatic error handling (switch statements, error maps), error tracking in monitoring systems, and client-side error translation (i18n).
Overrides
operation
readonlyoperation:string
Defined in: src/types/errors.ts:385
Type of database operation that failed.
Example
'CREATE', 'READ', 'UPDATE', 'DELETE', 'QUERY'