rsanchez
2017-04-17 f11e78dacb3bbf45988a5002bed3bf8e7f97d043
securis/src/main/webapp/src/app/common/utils.ts
....@@ -1,6 +1,6 @@
11
22 import { Component, Injectable, Input } from '@angular/core';
3
-import {LocaleService} from './i18n';
3
+import { LocaleService } from './i18n';
44 import { Observable } from 'rxjs/Observable';
55
66
....@@ -40,26 +40,23 @@
4040 @Injectable()
4141 export class BasicService {
4242
43
- constructor(protected $L: LocaleService) {}
43
+ constructor(protected $L: LocaleService) { }
4444
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>{};
4948 error.httpCode = errorResponse.status;
50
- }
49
+ error.code = errorResponse.headers.get(ERROR_CODE_MESSAGE_HEADER) || error.httpCode;
5150
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
+ }
5359
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
+ }
6562 }