Commit ecb39d2
rest: route all error paths through mapDataError sanitizer (M10.14)
Most CRUD handlers already used mapDataError, but the bulk endpoints
(batch/createMany/updateMany/deleteMany), metadata read/save/delete,
UI view resolution, and discovery all bare-bounced 'error.message'
directly to the client. That leaked driver-level dumps like:
SqliteError: insert into sys_user (...) values (...) returning *
^^^^^^^^^^^^^
table layout
…and bypassed the validation/permission envelopes M10.4 introduced.
Add a single sendError(res, error, object?) helper that:
- honors structured { status, code } errors (e.g. 422 from metadata
spec validators) but caps message length and strips stack noise
- otherwise delegates to mapDataError, which already handles
VALIDATION_FAILED, PERMISSION_DENIED, object-not-found,
unique-violation -> 409, and the catch-all SQL-leak sanitizer
(DATABASE_ERROR 500 with no SQL in the body)
Replace 11 bare 'res.status(...).json({ error: error.message })' sites
across registerDiscoveryRoutes/registerMetadataEndpoints/
registerUiEndpoints/registerCrudEndpoints. CRUD endpoints that already
used mapDataError directly are unchanged.
Verified end-to-end against running app-crm:
* Force missing-column on sys_user insert: client gets
{error:'Internal data error', code:'DATABASE_ERROR'} (500),
server log keeps the raw SqliteError for ops triage.
* Unknown object -> 404 object_not_found.
* Validation failure on POST /data/lead and /data/lead/createMany ->
400 VALIDATION_FAILED with per-field array (envelope from M10.4
preserved).
* Invalid metadata save -> 422 invalid_metadata (typed status pass-
through still works).
* All 53 @objectstack/rest tests pass.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 8bb6564 commit ecb39d2
1 file changed
Lines changed: 38 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
136 | 161 | | |
137 | 162 | | |
138 | 163 | | |
| |||
877 | 902 | | |
878 | 903 | | |
879 | 904 | | |
880 | | - | |
| 905 | + | |
881 | 906 | | |
882 | 907 | | |
883 | 908 | | |
| |||
925 | 950 | | |
926 | 951 | | |
927 | 952 | | |
928 | | - | |
| 953 | + | |
929 | 954 | | |
930 | 955 | | |
931 | 956 | | |
| |||
955 | 980 | | |
956 | 981 | | |
957 | 982 | | |
958 | | - | |
| 983 | + | |
959 | 984 | | |
960 | 985 | | |
961 | 986 | | |
| |||
1026 | 1051 | | |
1027 | 1052 | | |
1028 | 1053 | | |
1029 | | - | |
| 1054 | + | |
1030 | 1055 | | |
1031 | 1056 | | |
1032 | 1057 | | |
| |||
1071 | 1096 | | |
1072 | 1097 | | |
1073 | 1098 | | |
1074 | | - | |
1075 | | - | |
1076 | | - | |
1077 | | - | |
1078 | | - | |
| 1099 | + | |
1079 | 1100 | | |
1080 | 1101 | | |
1081 | 1102 | | |
| |||
1108 | 1129 | | |
1109 | 1130 | | |
1110 | 1131 | | |
1111 | | - | |
1112 | | - | |
1113 | | - | |
1114 | | - | |
1115 | | - | |
| 1132 | + | |
1116 | 1133 | | |
1117 | 1134 | | |
1118 | 1135 | | |
| |||
1144 | 1161 | | |
1145 | 1162 | | |
1146 | 1163 | | |
1147 | | - | |
| 1164 | + | |
1148 | 1165 | | |
1149 | 1166 | | |
1150 | 1167 | | |
| |||
1177 | 1194 | | |
1178 | 1195 | | |
1179 | 1196 | | |
1180 | | - | |
| 1197 | + | |
1181 | 1198 | | |
1182 | 1199 | | |
1183 | 1200 | | |
| |||
1214 | 1231 | | |
1215 | 1232 | | |
1216 | 1233 | | |
1217 | | - | |
| 1234 | + | |
1218 | 1235 | | |
1219 | 1236 | | |
1220 | 1237 | | |
| |||
1476 | 1493 | | |
1477 | 1494 | | |
1478 | 1495 | | |
1479 | | - | |
| 1496 | + | |
1480 | 1497 | | |
1481 | 1498 | | |
1482 | 1499 | | |
| |||
1506 | 1523 | | |
1507 | 1524 | | |
1508 | 1525 | | |
1509 | | - | |
| 1526 | + | |
1510 | 1527 | | |
1511 | 1528 | | |
1512 | 1529 | | |
| |||
1536 | 1553 | | |
1537 | 1554 | | |
1538 | 1555 | | |
1539 | | - | |
| 1556 | + | |
1540 | 1557 | | |
1541 | 1558 | | |
1542 | 1559 | | |
| |||
1566 | 1583 | | |
1567 | 1584 | | |
1568 | 1585 | | |
1569 | | - | |
| 1586 | + | |
1570 | 1587 | | |
1571 | 1588 | | |
1572 | 1589 | | |
| |||
0 commit comments