diff --git a/src/packages/core/rest/client/RESTClient.ts b/src/packages/core/rest/client/RESTClient.ts index b91da23..38a592f 100644 --- a/src/packages/core/rest/client/RESTClient.ts +++ b/src/packages/core/rest/client/RESTClient.ts @@ -9,7 +9,10 @@ import 'rxjs/add/operator/catch'; import 'rxjs/add/operator/timeout'; import 'rxjs/add/observable/throw'; -import { RESTError } from '../error'; +import { + RESTError, + RESTServerError, +} from '../error'; export class RESTClient { constructor( @@ -39,14 +42,23 @@ export class RESTClient { .request(method, Location.joinWithSlash(this._baseURL, entry), options) .map(response => response) .catch((error: HttpErrorResponse) => { - console.error(error); - const aryMsg = error.error.message.split('|'); - const resError: RESTError = { - code: error.error.code, - message: aryMsg[0], - data: aryMsg[1] === 'null' ? '' : aryMsg[1], + const restError: RESTError = { + request: { + method: method, + entry: entry, + options: options, + }, + response: error.error, }; - return Observable.throw(resError); + + console.error(restError); + // const aryMsg = error.error.message.split('|'); + // const resError: RESTError = { + // code: error.error.code, + // message: aryMsg[0], + // data: aryMsg[1] === 'null' ? '' : aryMsg[1], + // }; + return Observable.throw(restError); }); } } diff --git a/src/packages/core/rest/error.ts b/src/packages/core/rest/error.ts index e5942ff..659418c 100644 --- a/src/packages/core/rest/error.ts +++ b/src/packages/core/rest/error.ts @@ -1,4 +1,13 @@ export interface RESTError { + request: { + method: string; + entry: string; + options?: any; + }; + response: RESTServerError; +} + +export interface RESTServerError { code: number; message: string; data?: any; diff --git a/src/packages/core/rpc/client/RPCClient.ts b/src/packages/core/rpc/client/RPCClient.ts index 44be1c0..d8eb9e8 100644 --- a/src/packages/core/rpc/client/RPCClient.ts +++ b/src/packages/core/rpc/client/RPCClient.ts @@ -1,6 +1,8 @@ import { Observable } from 'rxjs/Observable'; import { Subject } from 'rxjs/Subject'; + +import { RPCError } from '../error'; import { RPCClientRWC } from './rwc/RPCClientRWC'; import { @@ -11,14 +13,17 @@ import { export interface RPCRequestState { subject: Subject; - request: any; + request: { + method: string; + params: any[]; + }; } export abstract class RPCClient { private _requestID: number; private _pendingRequestsCount: number; - private _pendingRequests: Map>; + private _pendingRequests: Map; public constructor( private _codec: RPCClientCodec, @@ -85,7 +90,14 @@ export abstract class RPCClient { if (hasResponse) { id = this.getRequestID(); resSubject = new Subject(); - this._pendingRequests.set(id, resSubject); + const reqState: RPCRequestState = { + subject: resSubject, + request: { + method: method, + params: args, + } + }; + this._pendingRequests.set(id, reqState); this._pendingRequestsCount++; } @@ -114,15 +126,20 @@ export abstract class RPCClient { const result = resCodec.result(); const error = resCodec.error(); - const resSubject: Subject = this._pendingRequests.get(id); + const reqState: RPCRequestState = this._pendingRequests.get(id); + this._pendingRequests.delete(id); this._pendingRequestsCount--; if (undefined !== result) { - resSubject.next(result); + reqState.subject.next(result); } else if (undefined !== error) { - console.error(error); - resSubject.error(error); + const rpcError: RPCError = { + request: reqState.request, + response: error, + }; + console.error(rpcError); + reqState.subject.error(rpcError); } } diff --git a/src/packages/core/rpc/error.ts b/src/packages/core/rpc/error.ts index 7d657bb..6997e0c 100644 --- a/src/packages/core/rpc/error.ts +++ b/src/packages/core/rpc/error.ts @@ -1,7 +1,15 @@ +export interface RPCError { + request: { + method: string, + params: any[], + }; + response: RPCServerError; +} + /** * Error object representation when a method invocation fails. */ -export interface RPCError { +export interface RPCServerError { /** Indicates the error type that occurred. */ code: ErrorCode; diff --git a/src/packages/core/rpc/protocol/RPCClientCodec.ts b/src/packages/core/rpc/protocol/RPCClientCodec.ts index e5de713..433ad9f 100644 --- a/src/packages/core/rpc/protocol/RPCClientCodec.ts +++ b/src/packages/core/rpc/protocol/RPCClientCodec.ts @@ -1,4 +1,4 @@ -import { RPCError } from '../error'; +import { RPCServerError } from '../error'; export abstract class RPCClientCodec { abstract request(method: string, args: any[], id: number): any; @@ -7,7 +7,7 @@ export abstract class RPCClientCodec { export abstract class RPCClientResponseCodec { abstract id(): number | undefined; - abstract error(): RPCError | undefined; + abstract error(): RPCServerError | undefined; abstract result(): any | undefined; abstract isNotification(): boolean; diff --git a/src/packages/core/rpc/protocol/json/RPCClientJSONCodec.ts b/src/packages/core/rpc/protocol/json/RPCClientJSONCodec.ts index d87534b..d6886a4 100644 --- a/src/packages/core/rpc/protocol/json/RPCClientJSONCodec.ts +++ b/src/packages/core/rpc/protocol/json/RPCClientJSONCodec.ts @@ -5,7 +5,7 @@ import { } from '../RPCClientCodec'; import { - RPCError, + RPCServerError, } from '../../error'; export interface ClientNotification { @@ -23,7 +23,7 @@ export interface ClientRequest { export interface ClientResponse { jsonrpc: string; result?: any; - error?: RPCError; + error?: RPCServerError; id?: number; } @@ -56,7 +56,7 @@ export class RPCClientJSONResponseCodec extends RPCClientResponseCodec { public id(): number | undefined { return this._res.id; } - public error(): RPCError | undefined { + public error(): RPCServerError | undefined { return this._res.error; } public result(): any | undefined { diff --git a/src/packages/discovery/store/setting/setting.effect.ts b/src/packages/discovery/store/setting/setting.effect.ts index fd26b6d..163016e 100644 --- a/src/packages/discovery/store/setting/setting.effect.ts +++ b/src/packages/discovery/store/setting/setting.effect.ts @@ -44,7 +44,7 @@ export class Effects { return new SettingSuccess(discoveryStartInfo); }) .catch((error: RPCError) => { - console.log(error.message); + console.log(error.response.message); return of(new SettingFailure(error)); }); } diff --git a/src/packages/infra/component/map/map.component.ts b/src/packages/infra/component/map/map.component.ts index 9c7116d..e46b257 100644 --- a/src/packages/infra/component/map/map.component.ts +++ b/src/packages/infra/component/map/map.component.ts @@ -34,7 +34,7 @@ export class MapComponent implements OnInit, AfterContentInit { } }, (error: RPCError) => { - console.log(error.message); + console.log(error.response.message); } ); } diff --git a/src/packages/noauth/component/list/list.component.ts b/src/packages/noauth/component/list/list.component.ts index e76ccc8..9347d88 100644 --- a/src/packages/noauth/component/list/list.component.ts +++ b/src/packages/noauth/component/list/list.component.ts @@ -45,13 +45,13 @@ export class ListComponent implements OnInit, AfterContentInit { this.dataSource.sort = this.sort; }, (error: RPCError) => { - console.log(error.message); + console.log(error.response.message); } ); } - - + + ngOnInit() { } @@ -67,7 +67,7 @@ export class ListComponent implements OnInit, AfterContentInit { this.dataSource.sort = this.sort; }, (error: RPCError) => { - console.log(error.message); + console.log(error.response.message); } ); console.log(this.selected.id + ' accept'); @@ -81,9 +81,9 @@ export class ListComponent implements OnInit, AfterContentInit { this.dataSource.sort = this.sort; }, (error: RPCError) => { - console.log(error.message); + console.log(error.response.message); } - ) + ); console.log(this.selected.id + ' deny'); } } diff --git a/src/packages/notification/component/badge/notification.component.ts b/src/packages/notification/component/badge/notification.component.ts index 72252df..ac1978b 100644 --- a/src/packages/notification/component/badge/notification.component.ts +++ b/src/packages/notification/component/badge/notification.component.ts @@ -38,7 +38,7 @@ export class NotificationBadgeComponent implements OnInit, AfterContentInit { } }, (error: RPCError) => { - console.log(error.message); + console.log(error.response.message); } ); this.mark$.subscribe( @@ -48,7 +48,7 @@ export class NotificationBadgeComponent implements OnInit, AfterContentInit { } }, (error: RPCError) => { - console.log(error.message); + console.log(error.response.message); } ); } diff --git a/src/packages/notification/component/notification/notification.component.ts b/src/packages/notification/component/notification/notification.component.ts index 8e0d7f5..1294ca2 100644 --- a/src/packages/notification/component/notification/notification.component.ts +++ b/src/packages/notification/component/notification/notification.component.ts @@ -40,7 +40,7 @@ export class NotificationComponent implements OnInit, AfterContentInit { } }, (error: RPCError) => { - console.log(error.message); + console.log(error.response.message); } ); } diff --git a/src/packages/notification/store/detail/notification.effect.ts b/src/packages/notification/store/detail/notification.effect.ts index 9cf9be0..7564818 100644 --- a/src/packages/notification/store/detail/notification.effect.ts +++ b/src/packages/notification/store/detail/notification.effect.ts @@ -44,7 +44,7 @@ export class Effects { return new MarkAsReadSuccess(notification); }) .catch((error: RPCError) => { - console.log(error.message); + console.log(error.response.message); return of(new MarkAsReadFailure(error)); }); } diff --git a/src/packages/notification/store/list/notification.effect.ts b/src/packages/notification/store/list/notification.effect.ts index 2a8b240..1e57a67 100644 --- a/src/packages/notification/store/list/notification.effect.ts +++ b/src/packages/notification/store/list/notification.effect.ts @@ -58,7 +58,7 @@ export class Effects { return new MarkAllAsReadSuccess(page); }) .catch((error: RPCError) => { - console.log('errrrrrrrrrrrrrr : ' + error.message); + console.log('errrrrrrrrrrrrrr : ' + error.response.message); return of(new MarkAllAsReadFailure(error)); }); } diff --git a/src/packages/probe/component/detail/detail.component.ts b/src/packages/probe/component/detail/detail.component.ts index 2ac053d..312cf14 100644 --- a/src/packages/probe/component/detail/detail.component.ts +++ b/src/packages/probe/component/detail/detail.component.ts @@ -41,7 +41,7 @@ export class DetailComponent implements OnInit, AfterContentInit { } }, (error: RPCError) => { - console.log(error.message); + console.log(error.response.message); } ); } diff --git a/src/packages/probe/component/list/list.component.ts b/src/packages/probe/component/list/list.component.ts index 0a6178c..3d9088f 100644 --- a/src/packages/probe/component/list/list.component.ts +++ b/src/packages/probe/component/list/list.component.ts @@ -50,7 +50,7 @@ export class ListComponent implements OnInit, AfterContentInit { this.dataSource.sort = this.sort; }, (error: RPCError) => { - console.log(error.message); + console.log(error.response.message); } ); diff --git a/src/packages/sensor/component/list/list.component.ts b/src/packages/sensor/component/list/list.component.ts index d231e35..128bd90 100644 --- a/src/packages/sensor/component/list/list.component.ts +++ b/src/packages/sensor/component/list/list.component.ts @@ -70,7 +70,7 @@ export class ListComponent implements OnInit, AfterContentInit { this.dataSource.sort = this.sort; }, (error: RPCError) => { - console.log(error.message); + console.log(error.response.message); } );