<commit_before>import { Observable } from 'rxjs/Observable';
import { AppError, HttpAppError } from './error.model';
import { LoggerService } from '../services/logger.service';

export class ErrorHandler {

  /**
   * Generate the error message that will be used and throw the appropriate exception.
   * @param error the exception that was thrown by the http post.
   * @returns {any} Exception to be thrown by the Observable
   */
  public handleError(error: Response | any) {
    const errorObject = {
      status: 0,
      message: ''
    };

    if (error instanceof Response) {
      let body;
      errorObject.status = error.status;
      try {
        body = error.json() || '';
      } catch (e) {
        LoggerService.log('Unparsable json', error);
        errorObject.message = `${error.text()} (Status code: ${error.status})`;
      }
      if (body) {
        let isFirst = true;
        for (const bodyElement of body) {
          if (!isFirst) {
            errorObject.message += '\n';
          } else {
            isFirst = false;
          }
          errorObject.message += bodyElement.message;
        }
      }
      return Observable.throwError(new HttpAppError(errorObject.message, errorObject.status));
    } else {
      errorObject.message = error.message ? error.message : error.toString();
      return Observable.throwError(new AppError(errorObject.message));
    }
  }

}

<commit_msg>Error handle: update parsing HTTP Error<commit_after>import { Observable } from 'rxjs/Observable';
import { AppError, HttpAppError } from './error.model';
import { LoggerService } from '../services/logger.service';
import { HttpErrorResponse } from '@angular/common/http';

export class ErrorHandler {

  /**
   * Generate the error message that will be used and throw the appropriate exception.
   * @param error the exception that was thrown by the http post.
   * @returns {any} Exception to be thrown by the Observable
   */
  public handleError(error: Response | any) {
    const errorObject = {
      status: 0,
      message: ''
    };
    if (error instanceof HttpErrorResponse) {
      let body;
      errorObject.status = error.status;
      try {
        body = error.error || '';
      } catch (e) {
        LoggerService.log('Unparsable json', error);
        errorObject.message = `${error} (Status code: ${error.status})`;
      }
      if (body) {
        let isFirst = true;
        for (const bodyElement of body) {
          if (!isFirst) {
            errorObject.message += '\n';
          } else {
            isFirst = false;
          }
          errorObject.message += bodyElement.message;
        }
      }
      return Observable.throwError(new HttpAppError(errorObject.message, errorObject.status));
    } else {
      errorObject.message = error.message ? error.message : error.toString();
      return Observable.throwError(new AppError(errorObject.message));
    }
  }

}


{'fraction_non_alphanumeric': 0.11559507523939809, 'fraction_numerical': 0.0006839945280437756, 'mean_word_length': 2.4492924528301887, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5272933', 'n_tokens_mistral': 795, 'n_tokens_neox': 790, 'n_words': 229}