import {Injectable, ErrorHandler} from '@angular/core';
import {Response} from "@angular/http";
import {Observable} from "rxjs";

@Injectable()
export class ErrorHandlerService implements ErrorHandler {

  constructor() { }

  /*
   * @description: handler for http-request catch-clauses
   */
  handleError(error: Response | any) {
    let errorMessage: string;

    if (error instanceof Response) {
      const body = error.json() || '';
      const err = body.error || JSON.stringify(body);
      errorMessage = `${error.status} - ${error.statusText || ''} ${err}`;
    } else {
      errorMessage = error.message ? error.message : error.toString();
    }

    return Observable.throw(errorMessage);
  }


}

import {Injectable, ErrorHandler} from '@angular/core';
import {Response} from "@angular/http";
import {Observable} from "rxjs";

@Injectable()
export class ErrorHandlerService implements ErrorHandler {

  constructor() { }

  /*
   * @description: handler for http-request catch-clauses
   */
  handleError(error: Response | any) {
    let errorMessage: string;

    if (error instanceof Response) {
      //const body = error.json() || '';
      //const err = body.error || JSON.stringify(body);
      const err = error.text() || '';
      errorMessage = `${error.status} - ${error.statusText || ''} (${err})`;
    } else {
      errorMessage = error.message ? error.message : error.toString();
    }

    return Observable.throw(errorMessage);
  }


}

Handle errors as plain text
Handle errors as plain text
