@@ -8,53 +8,56 @@ module.exports = function(err) {
88
99 // PostgreSQL uses 5-character SQLSTATE error codes
1010 switch ( err . code ) {
11- // Unique Violation (e.g., duplicate key value violates unique constraint)
12- case '23505' :
11+ // 1. Data Integrity & Constraints
12+ case '23505' : // unique_violation
1313 err . code = 'UNIQUE_CONSTRAINT_VIOLATION' ;
1414 break ;
15-
16- // Undefined Table (relation "..." does not exist)
17- case '42P01' :
18- err . code = 'TABLE_NOT_FOUND' ;
19- break ;
20-
21- // Foreign Key Violation (violates foreign key constraint)
22- case '23503' :
23- // Exclusion Violation
24- case '23P01' :
15+ case '23503' : // foreign_key_violation
16+ case '23P01' : // exclusion_violation
2517 err . code = 'FOREIGN_KEY_VIOLATION' ;
2618 break ;
27-
28- // Not Null Violation (null value in column violates not-null constraint)
29- case '23502' :
19+ case '23502' : // not_null_violation
3020 err . code = 'NOT_NULL_VIOLATION' ;
3121 break ;
32-
33- // Check Violation (new row for relation violates check constraint)
34- case '23514' :
22+ case '23514' : // check_violation
3523 err . code = 'CHECK_CONSTRAINT_VIOLATION' ;
3624 break ;
3725
38- // Data Exception (numeric value out of range, string data right truncation, invalid text representation)
39- case '22001' :
40- case '22003' :
41- case '22P02' :
26+ // 2. Schema & Object Definitions
27+ case '42P01' : // undefined_table
28+ err . code = 'TABLE_NOT_FOUND' ;
29+ break ;
30+ case '42703' : // undefined_column
31+ err . code = 'COLUMN_NOT_FOUND' ;
32+ break ;
33+
34+ // 3. Data Formatting & Types
35+ case '22001' : // string_data_right_truncation
36+ case '22003' : // numeric_value_out_of_range
37+ case '22P02' : // invalid_text_representation
4238 err . code = 'DATA_TYPE_MISMATCH' ;
4339 break ;
4440
45- // Deadlock Detected / Lock Not Available
46- case '40P01' :
47- case '55P03' :
41+ // 4. Concurrency & Execution
42+ case '40001' : // serialization_failure
43+ case '40P01' : // deadlock_detected
44+ case '55P03' : // lock_not_available
4845 err . code = 'LOCK_CONFLICT' ;
4946 break ;
47+ case '57014' : // query_canceled
48+ err . code = 'QUERY_TIMEOUT' ;
49+ break ;
50+ case '42601' : // syntax_error
51+ err . code = 'SYNTAX_ERROR' ;
52+ break ;
5053
51- // Connection Exception / Cannot Connect Now / Server Shut Down / Crash Shutdown
52- case '08000' :
53- case '08003' :
54- case '08006' :
55- case '57P01' :
56- case '57P02' :
57- case '57P03' :
54+ // 5. Infrastructure & Connection
55+ case '08000' : // connection_exception
56+ case '08003' : // connection_does_not_exist
57+ case '08006' : // connection_failure
58+ case '57P01' : // admin_shutdown
59+ case '57P02' : // crash_shutdown
60+ case '57P03' : // cannot_connect_now
5861 err . code = 'CONNECTION_FAILURE' ;
5962 break ;
6063 }
0 commit comments