practica
practica copied to clipboard
Error handler improvements
Our handler looks awesome, with that we might have another iteration to perfect it?
What can be improved:
- The tests should focus on the outcome down to the field level
- See attached coverage report, some important paths are uncovered
- We don't test the existence/handling of the last AppError param: cause
- I would change AppError.isTrusted to AppError.isFatal
- We lose additional error properties of custom errors: Consider AxiosError.status or MongooseError.someProperty, our handler won't copy these important unknown properties
A. For the case of Error object -> The normalizer can use the origin error object (which already has the stack) and then just thoughtfully copy missing properties:
enrichedError = errorToHandle as AppError
enrichedError.name = errorToHandle.name?? 'General error'
// more properties
B. For the case of non-error object -> We may create AppError, then blend in all the properties from the non-error
const enrichedError = new AppError('General error', ...)
object.assign(enrichedError, errorToHandle)
Or is there a better way? In any case, let's simulate those things in our testing (e.g., non-error with some custom properties)
@goldbergyoni Thank you, will get into that soon :)
@RonDaha This feature is still open? @goldbergyoni What can be my next contribution?