| .. | .. |
|---|
| 1 | 1 | |
|---|
| 2 | 2 | import { Component, Injectable, Input } from '@angular/core'; |
|---|
| 3 | | -import {LocaleService} from './i18n'; |
|---|
| 3 | +import { LocaleService } from './i18n'; |
|---|
| 4 | 4 | import { Observable } from 'rxjs/Observable'; |
|---|
| 5 | 5 | |
|---|
| 6 | 6 | |
|---|
| .. | .. |
|---|
| 40 | 40 | @Injectable() |
|---|
| 41 | 41 | export class BasicService { |
|---|
| 42 | 42 | |
|---|
| 43 | | - constructor(protected $L: LocaleService) {} |
|---|
| 43 | + constructor(protected $L: LocaleService) { } |
|---|
| 44 | 44 | |
|---|
| 45 | | - public processErrorResponse(errorResponse: Response | any) { |
|---|
| 46 | | - // In a real world app, we might use a remote logging infrastructure |
|---|
| 47 | | - var error: IError = <IError>{}; |
|---|
| 48 | | - if (errorResponse instanceof Response) { |
|---|
| 45 | + public processErrorResponse(errorResponse: Response) { |
|---|
| 46 | + // In a real world app, we might use a remote logging infrastructure |
|---|
| 47 | + var error: IError = <IError>{}; |
|---|
| 49 | 48 | error.httpCode = errorResponse.status; |
|---|
| 50 | | - } |
|---|
| 49 | + error.code = errorResponse.headers.get(ERROR_CODE_MESSAGE_HEADER) || error.httpCode; |
|---|
| 51 | 50 | |
|---|
| 52 | | - error.code = errorResponse.headers.get(ERROR_CODE_MESSAGE_HEADER) || error.httpCode; |
|---|
| 51 | + if (errorResponse.status === 403 /* forbidden */ || errorResponse.status === 401 /* unauthorized */) { |
|---|
| 52 | + error.message = this.$L.get('Invalid credentials'); |
|---|
| 53 | + error.code = ErrorCodes.INVALID_CREDENTIALS; |
|---|
| 54 | + } else if (errorResponse.status === 418 /* Teapot */) { |
|---|
| 55 | + error.message = errorResponse.headers.get(ERROR_MESSAGE_HEADER) || errorResponse.statusText || this.$L.get('Unknown'); |
|---|
| 56 | + } else { |
|---|
| 57 | + error.message = this.$L.get(`Unexpected error HTTP (${error.httpCode}) accessing to server. Contact with the administrator.`); |
|---|
| 58 | + } |
|---|
| 53 | 59 | |
|---|
| 54 | | - if (errorResponse.status === 403 /* forbidden */ || errorResponse.status === 401 /* unauthorized */) { |
|---|
| 55 | | - error.message = this.$L.get('Invalid credentials'); |
|---|
| 56 | | - error.code = ErrorCodes.INVALID_CREDENTIALS; |
|---|
| 57 | | - } else if (errorResponse.status === 418 /* Teapot */) { |
|---|
| 58 | | - error.message = errorResponse.headers.get(ERROR_MESSAGE_HEADER) || errorResponse.statusText || this.$L.get('Unknown'); |
|---|
| 59 | | - } else { |
|---|
| 60 | | - error.message = this.$L.get(`Unexpected error HTTP (${error.httpCode}) accessing to server. Contact with the administrator.`); |
|---|
| 61 | | - } |
|---|
| 62 | | - |
|---|
| 63 | | - return Observable.throw(error); |
|---|
| 64 | | - } |
|---|
| 60 | + return Observable.throw(error); |
|---|
| 61 | + } |
|---|
| 65 | 62 | } |
|---|