From 1a0491f2462d2c309bd8e310b22c11019a79ce1e Mon Sep 17 00:00:00 2001
From: rsanchez <rsanchez@curisit.net>
Date: Mon, 20 Mar 2017 16:02:14 +0000
Subject: [PATCH] #3527 fix - Added applications forms and metadata component
---
securis/src/main/webapp/src/app/common/utils.ts | 101 +++++++++++++++++++++++++++++---------------------
1 files changed, 58 insertions(+), 43 deletions(-)
diff --git a/securis/src/main/webapp/src/app/common/utils.ts b/securis/src/main/webapp/src/app/common/utils.ts
index 7620961..25ce5d9 100644
--- a/securis/src/main/webapp/src/app/common/utils.ts
+++ b/securis/src/main/webapp/src/app/common/utils.ts
@@ -1,50 +1,65 @@
-import {Component, Input} from '@angular/core';
+import { Component, Injectable, Input } from '@angular/core';
import {LocaleService} from './i18n';
+import { Observable } from 'rxjs/Observable';
-@Component({
- selector: 'field-readonly',
- template: `
- <div layout="column" class="mat-input-container readonly" >
- <div class="mat-input-wrapper">
- <div class="mat-input-table">
- <div class="mat-input-prefix"></div>
- <div class="mat-input-infix">
- <div class="label-value mat-input-element">{{value}}</div>
- <span class="mat-input-placeholder-wrapper" >
- <label class="mat-input-placeholder mat-float">
- <span class="placeholder">{{label}}</span>
- </label>
- </span>
- </div>
- <div class="mat-input-suffix"></div>
- </div>
- <div class="mat-input-underline"></div>
- </div>
- </div>`,
- styles: [`.readonly .mat-input-element {
- margin-top: 0px !important;
- color: rgba(0, 0, 0, 0.50);
- }`,
- `.readonly .mat-input-element {
- margin-top: 0px;
- color: rgba(0, 0, 0, 0.50);
- }`,
- `.readonly.mat-input-container {
- width: 100%;
- }`]
-})
-export class FieldReadonlyComponent {
- @Input('value') value: any;
- private _label : string;
- @Input('label')
- set label(txt: string) {
- this._label = this.$L.get(txt);
- }
- get label(): string { return this._label; }
- constructor(private $L : LocaleService) {
+export interface IError {
+ code: string | number,
+ message: string,
+ httpCode?: number
+}
- }
+export const DEFAULT_APP_ERROR_STATUS_CODE = 418;
+export const ERROR_MESSAGE_HEADER = "X-SECURIS-ERROR-MSG";
+export const ERROR_CODE_MESSAGE_HEADER = "X-SECURIS-ERROR-CODE";
+
+export class ErrorCodes {
+ public static UNEXPECTED_ERROR = 1000;
+ public static INVALID_CREDENTIALS = 1001;
+ public static UNAUTHORIZED_ACCESS = 1002;
+ public static NOT_FOUND = 1003;
+ public static INVALID_FORMAT = 1004;
+ public static WRONG_STATUS = 1005;
+
+ public static INVALID_LICENSE_REQUEST_DATA = 1100;
+ public static LICENSE_NOT_READY_FOR_RENEW = 1101;
+ public static LICENSE_DATA_IS_NOT_VALID = 1102;
+ public static LICENSE_IS_EXPIRED = 1103;
+
+ public static INVALID_REQUEST_DATA = 1201;
+ public static INVALID_REQUEST_DATA_FORMAT = 1202;
+ public static BLOCKED_REQUEST_DATA = 1203;
+ public static DUPLICATED_REQUEST_DATA = 1204;
+ public static NO_AVAILABLE_LICENSES = 1205;
+
+ public static INVALID_DATA = 1301;
+}
+
+@Injectable()
+export class BasicService {
+
+ constructor(protected $L: LocaleService) {}
+
+ public processErrorResponse(errorResponse: Response | any) {
+ // In a real world app, we might use a remote logging infrastructure
+ var error: IError = <IError>{};
+ if (errorResponse instanceof Response) {
+ error.httpCode = errorResponse.status;
+ }
+
+ error.code = errorResponse.headers.get(ERROR_CODE_MESSAGE_HEADER) || error.httpCode;
+
+ if (errorResponse.status === 403 /* forbidden */ || errorResponse.status === 401 /* unauthorized */) {
+ error.message = this.$L.get('Invalid credentials');
+ error.code = ErrorCodes.INVALID_CREDENTIALS;
+ } else if (errorResponse.status === 418 /* Teapot */) {
+ error.message = errorResponse.headers.get(ERROR_MESSAGE_HEADER) || errorResponse.statusText || this.$L.get('Unknown');
+ } else {
+ error.message = this.$L.get(`Unexpected error HTTP (${error.httpCode}) accessing to server. Contact with the administrator.`);
+ }
+
+ return Observable.throw(error);
+ }
}
\ No newline at end of file
--
Gitblit v1.3.2