[CORD-2827] Fixed unauthorized error handling

Change-Id: I6ddef7f869c17db4d8479f23f6e8734f6002d8fc
diff --git a/src/app/datasources/rest/auth.rest.spec.ts b/src/app/datasources/rest/auth.rest.spec.ts
index 8ba77d3..044cf88 100644
--- a/src/app/datasources/rest/auth.rest.spec.ts
+++ b/src/app/datasources/rest/auth.rest.spec.ts
@@ -106,36 +106,36 @@
     });
   });
 
-  describe('the handleUnauthenticatedRequest method', () => {
+  describe('the isAuthError method', () => {
 
     beforeEach(() => {
       spyOn(service, 'clearUser');
     });
 
     it('should logout the user and redirect to login', () => {
-      service.handleUnauthenticatedRequest({
+      let res = service.isAuthError({
         error: 'XOSPermissionDenied',
         fields: {},
         specific_error: 'test'
       });
-      expect(service.clearUser).toHaveBeenCalled();
+      expect(res).toBeTruthy();
     });
 
     it('should catch errors from strings', () => {
-      service.handleUnauthenticatedRequest('{"fields": {}, "specific_error": "failed to authenticate token g09et150o2s25kdzg8t2n9wotvds9jyl", "error": "XOSPermissionDenied"}');
-      expect(service.clearUser).toHaveBeenCalled();
+      let res = service.isAuthError('{"fields": {}, "specific_error": "failed to authenticate token g09et150o2s25kdzg8t2n9wotvds9jyl", "error": "XOSPermissionDenied"}');
+      expect(res).toBeTruthy();
     });
 
     it('should not catch other errors', () => {
-      service.handleUnauthenticatedRequest({
+      let res = service.isAuthError({
         error: 'XOSProgrammingError',
         fields: {},
         specific_error: 'test'
       });
-      expect(service.clearUser).not.toHaveBeenCalled();
+      expect(res).toBeFalsy();
 
-      service.handleUnauthenticatedRequest('some error');
-      expect(service.clearUser).not.toHaveBeenCalled();
+      res = service.isAuthError('some error');
+      expect(res).toBeFalsy();
     });
   });
 });
diff --git a/src/app/datasources/rest/auth.rest.ts b/src/app/datasources/rest/auth.rest.ts
index 2bc2bbc..0c202b0 100644
--- a/src/app/datasources/rest/auth.rest.ts
+++ b/src/app/datasources/rest/auth.rest.ts
@@ -46,7 +46,7 @@
   getUser(): any; // NOTE how to define return user || false ???
   isAuthenticated(): boolean;
   clearUser(): void;
-  handleUnauthenticatedRequest(error: IXosRestError | string): void;
+  isAuthError(error: IXosRestError | string): boolean;
 }
 export class AuthService {
 
@@ -111,7 +111,7 @@
     return angular.isDefined(session);
   }
 
-  public handleUnauthenticatedRequest(res: IXosRestError | string): void {
+  public isAuthError(res: IXosRestError | string): boolean {
     let err;
     if (angular.isString(res)) {
       try {
@@ -129,9 +129,7 @@
     if (err && err.error) {
       switch (err.error) {
         case 'XOSPermissionDenied':
-          this.clearUser();
-          this.$state.go('login');
-          break;
+          return true;
       }
     }
   }
diff --git a/src/app/datasources/rest/modeldefs.rest.ts b/src/app/datasources/rest/modeldefs.rest.ts
index 60fc917..38ffb16 100644
--- a/src/app/datasources/rest/modeldefs.rest.ts
+++ b/src/app/datasources/rest/modeldefs.rest.ts
@@ -18,6 +18,7 @@
 
 import {IXosModelDefsField} from '../../core/services/helpers/config.helpers';
 import {IXosAppConfig} from '../../../index';
+import IPromise = angular.IPromise;
 
 export interface IXosModelDefsRelation {
   model: string; // model name
@@ -35,7 +36,7 @@
 }
 
 export interface IXosModeldefsService {
-  get(): Promise<IXosModeldef[]>;
+  get(): IPromise<IXosModeldef[]>;
 }
 
 export class XosModeldefsService implements IXosModeldefsService {
@@ -49,9 +50,9 @@
   ) {
   }
 
-  public get(): Promise<any> {
+  public get(): IPromise<IXosModeldef[]> {
     const d = this.$q.defer();
-    this.$http.get(`${this.AppConfig.apiEndpoint}/modeldefs`)
+    this.$http.get(`${this.AppConfig.apiEndpoint}/modeldefs`, {timeout: 5 * 1000})
       .then((res: any) => {
         d.resolve(res.data.items);
       })