Cases API: Unhandled TypeError on undefined rows in CaseController.submit
DomainQUERYKEY
ImpactMedium
Error Signature
querykey:cases-api:unhandled-rejection-cannot-read-properties
db.js query() returns undefined during pool exhaustion causing CaseController.submit to access .id on undefined.
Root Cause
The db.js query helper destructures pool.execute() result with const [rows] = result. When the MariaDB pool is exhausted, execute() yields [undefined, fields], making rows undefined. Downstream code in CaseController.submit accesses rows[0].id without a null guard, producing an unhandled TypeError in Express 4.x async context.
Solution Steps
- In db.js query() helper: after pool.execute(), add a guard: if (!Array.isArray(rows)) return [] — handles pool exhaustion where execute() returns [undefined, fields] rather than [Array, fields].
- In CaseController.submit: add null guard before accessing rows[0].id. Validate rows is a non-empty array and return 404 if not, preventing the unhandled TypeError in the Express 4.x async context.
Validation
[object Object]
Ecosystem: querykey
License: CC-BY-4.0
Last updated: May 21, 2026