Add data normalization and validation. Add validation error error type.

Add lookup by code method to pis class.
This commit is contained in:
2026-02-21 19:28:26 +00:00
parent edca2698a7
commit 16bb7d3510
4 changed files with 112 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
import { OwlBoardClient } from '../../src/lib/client';
import { ApiError } from '../../src/lib/errors';
import { ApiError, ValidationError } from '../../src/lib/errors';
console.log("Manual PIS Tests are running")
@@ -30,7 +30,7 @@ console.log("Server is reachable. Running tests...")
const {data, producedAt} = await api.pis.getByStartEndCrs(start, end);
console.log('\n---Response Success---');
console.log(`Data Produced At: ${producedAt.toLocaleTimeString()}`);
console.log(`Number of entries in response: ${data.length}`);
console.log(JSON.stringify(data));
} catch (err) {
if (err instanceof ApiError) {
@@ -38,12 +38,43 @@ console.log("Server is reachable. Running tests...")
console.error(`Code: ${err.code}`);
console.error(`Msg: ${err.message}`);
console.error(`Status: ${err.status}`);
} else if (err instanceof ValidationError) {
console.error('\n--- Local Validation Error ---');
console.error(`Error Field: ${err.field}`);
console.error(`Message: ${err.reason}`);
console.error(`Request not sent`);
} else {
console.error(`Unknown Error: ${err}`)
}
}
}
// Test PIS Code
{
const code = 5001;
console.log(`Querying PIS Code: ${code}`);
try {
const {data, producedAt} = await api.pis.getByCode(code.toString());
console.log("\n--- Response Success ---");
console.log(`Data produced at: ${producedAt.toLocaleString()}`);
console.log(`Number of results: ${data.length}`);
console.log(JSON.stringify(data));
} catch (err) {
if (err instanceof ApiError) {
console.error('\n--- API Error ---');
console.error(`Code: ${err.code}`);
console.error(`Msg: ${err.message}`);
console.error(`Status: ${err.status}`);
} else if (err instanceof ValidationError) {
console.error('\n--- Local Validation Error ---');
console.error(`Error Field: ${err.field}`);
console.error(`Message: ${err.reason}`);
console.error(`Request not sent`);
} else {
console.error(`Unknown Error: ${err}`)
}
}
}
};
main();