API V3: Implement Structured Error Handling and Validation Tests

- Updated api_get_object and api_post_object to extract rich metadata (meta.details) from 400/500 responses.
- Enables frontend to bubble up specific DB schema, validation, and constraint errors for better debugging.
- Added 'V3 Hardening' section to /testing dashboard with automated tests for Permissive Mode and Structured Error extraction.
This commit is contained in:
Scott Idem
2026-01-19 17:38:05 -05:00
parent 8566917be1
commit c40a296a77
3 changed files with 96 additions and 8 deletions

View File

@@ -164,19 +164,34 @@ export const post_object = async function post_object({
if (!response.ok) {
if (response.status === 404) {
console.warn('404 Not Found. Returning null.');
if (log_lvl) {
console.log('The response was a 404 not found "error". Returning null.');
}
return null;
}
const errorBody = await response.text();
console.error(`HTTP error! status: ${response.status}`, errorBody);
// Don't retry on client errors (400, 401, 403)
if (response.status >= 400 && response.status < 404) {
// FAIL FAST (Section 2D): Do not retry on Auth/Permission failures
if (response.status === 401 || response.status === 403) {
console.error(`API Auth Failure (${response.status}). Failing fast as per Section 2D protocol.`);
return false;
}
throw new Error(`HTTP error! status: ${response.status} - ${errorBody}`);
// Structured Error Handling (V3): Attempt to get rich error metadata
let error_json: any = null;
try {
error_json = await response.json();
} catch (e) {
// Not JSON
}
if (log_lvl) console.log('The response was not ok. Structured Error Check:', error_json);
if (error_json?.meta?.details) {
// Return the rich error object so caller can handle specific categories (database_schema, etc)
return error_json;
}
throw new Error(`HTTP error! status: ${response.status}`);
}
if (!return_blob) {