practica icon indicating copy to clipboard operation
practica copied to clipboard

Error handler improvements

Open goldbergyoni opened this issue 2 years ago • 2 comments

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)

image

goldbergyoni avatar Jul 25 '22 09:07 goldbergyoni

@goldbergyoni Thank you, will get into that soon :)

RonDaha avatar Jul 26 '22 06:07 RonDaha

@RonDaha This feature is still open? @goldbergyoni What can be my next contribution?

marcosmol204 avatar Dec 11 '22 21:12 marcosmol204