about - tech blog -
mesazero.com

Mesazero's Technology Blog
An occasionally updated list of informative articles.
Pulled from our internal wiki.

Angular - Dumb Error Dumper

2025-06-11

Angular - Dumb Error Dumper

Angular - Dumb error dump.

Getting Validators right for a complex reactive form can be a challenge so being able to just dump all validation errors is very useful as a diagnostic.

getAllErrors(): object[] {
  const returner: object[] = [];
  Object.keys(this.controls).forEach((key) => {
    const controlErrors: ValidationErrors | null | undefined = this.get(key)?.errors;
    if (controlErrors) {
      Object.keys(controlErrors).forEach((keyError) => {
        returner.push({
          'key': key,
          'error': keyError,
          'error value': controlErrors[keyError],
        });
      });
    } // controlErrors?
  }); // forEach
  return returner;
}

This function is intended to be added inside a class that extends FormGroup. For more complex forms, we find it better to pull the form into its own class so it doesn't clutter up the component driving the page.

It just finds all controls for the form, checks for errors, then adds them to a big array it sends back to the calling page.

Very useful with PrettyJsonPipe.

Back to the Tech Blog
Blog engine: 1.5.0