Could you export ArgumentError class from package?
Yes, I can check the error's type by err.name === 'ArgumentError' but this stands out from the approach adopted by our team. Schematically:
async function updateById(id, data) {
try {
ow(id, ow.number.integer.greaterThanOrEqual(0).finite);
ow(data, ow.object);
const result = await db.updateById(id, data);
// ...
} catch (err) {
if (err instanceof DBError) {
if (err instanceof NotFoundError) {
// ...
} else if (err instanceof ConstraintViolationError) {
// ...
} // else if (err instanceof ...) { ... }
}
// here:
else if (err.name === 'ArgumentError') { /* ... */ }
}
}
It would be cool to use ArgumentError like this:
import ow, { ArgumentError } from 'ow';
// ...
if (err instanceof ArgumentError) { /* ... */ }
In addition, we get the possibility of static analysis and instead of searching by all project by "ArgumentError" string, the editor/IDE will be able to show all the places where this error is catched/handled.
Hi! Thank you for
ow
!Could you export
ArgumentError
class from package?Yes, I can check the error's type by
err.name === 'ArgumentError'
but this stands out from the approach adopted by our team. Schematically:It would be cool to use
ArgumentError
like this:In addition, we get the possibility of static analysis and instead of searching by all project by "ArgumentError" string, the editor/IDE will be able to show all the places where this error is catched/handled.
p.s. yes, I'm js-only user, not ts =)