WebSocket Error handling
This commit is contained in:
parent
7f404448ec
commit
58b1823b83
|
@ -1,4 +1,5 @@
|
||||||
import {
|
import {
|
||||||
|
ErrorCode,
|
||||||
Notification,
|
Notification,
|
||||||
Request,
|
Request,
|
||||||
Response,
|
Response,
|
||||||
|
@ -30,6 +31,11 @@ enum WebSocketReadyState {
|
||||||
CLOSED = 3,
|
CLOSED = 3,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface RuntimeError {
|
||||||
|
type: string;
|
||||||
|
data?: any;
|
||||||
|
}
|
||||||
|
|
||||||
export default class WebSocketRPC {
|
export default class WebSocketRPC {
|
||||||
private url: string;
|
private url: string;
|
||||||
private connStatus: WebSocketStatus;
|
private connStatus: WebSocketStatus;
|
||||||
|
@ -145,7 +151,14 @@ export default class WebSocketRPC {
|
||||||
console.log(result);
|
console.log(result);
|
||||||
promise.resolve(result);
|
promise.resolve(result);
|
||||||
} else if (null != error) {
|
} else if (null != error) {
|
||||||
promise.reject(error);
|
if (ErrorCode.E_RUNTIME === error.Code) {
|
||||||
|
const runTimeError: RuntimeError = {
|
||||||
|
type: error.Message,
|
||||||
|
};
|
||||||
|
promise.reject(runTimeError);
|
||||||
|
} else {
|
||||||
|
console.log(`System error[${error.Code}|${error.Message}|${error.Data}]`);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log('??????');
|
console.log('??????');
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
export const enum ErrorCode {
|
export const enum ErrorCode {
|
||||||
|
E_RUNTIME = -33000,
|
||||||
E_PARSE = -32700,
|
E_PARSE = -32700,
|
||||||
E_INVALID_REQ = -32600,
|
E_INVALID_REQ = -32600,
|
||||||
E_NO_METHOD = -32601,
|
E_NO_METHOD = -32601,
|
||||||
|
@ -22,26 +23,30 @@ export class ProtocolError {
|
||||||
/**
|
/**
|
||||||
* getID
|
* getID
|
||||||
*/
|
*/
|
||||||
public getCode(): ErrorCode {
|
public get Code(): ErrorCode {
|
||||||
return this.code;
|
return this.code;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getBody
|
* getBody
|
||||||
*/
|
*/
|
||||||
public getMessage(): string {
|
public get Message(): string {
|
||||||
return this.message;
|
return this.message;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getError
|
* getError
|
||||||
*/
|
*/
|
||||||
public getData(): any {
|
public get Data(): any {
|
||||||
return this.data;
|
return this.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static newError(json: string): ProtocolError {
|
public static convert(error: ProtocolError): ProtocolError {
|
||||||
return JSON.parse(json);
|
const code = error.code;
|
||||||
|
if (undefined === code) {
|
||||||
|
throw new Error(`Error must include Code`);
|
||||||
|
}
|
||||||
|
return new ProtocolError(code, error.message, error.data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ export class Response<ID> extends Header {
|
||||||
let res = new Response(id);
|
let res = new Response(id);
|
||||||
res.Protocol = response.protocol;
|
res.Protocol = response.protocol;
|
||||||
res.result = response.result;
|
res.result = response.result;
|
||||||
res.error = response.error;
|
res.error = ProtocolError.convert(response.error);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ export function mapDispatchToProps(dispatch: Dispatch<any>, ownProps?: any): Sig
|
||||||
return {
|
return {
|
||||||
onSignIn: (signinId: string, signinPw: string) => {
|
onSignIn: (signinId: string, signinPw: string) => {
|
||||||
// dispatch(signinActions.request(signinId, signinPw));
|
// dispatch(signinActions.request(signinId, signinPw));
|
||||||
dispatch(asyncRequestActions.request('MemberService', 'signin', signinActions.REQUEST, signinId, signinPw));
|
dispatch(asyncRequestActions.request('MemberService1', 'signin', signinActions.REQUEST, signinId, signinPw));
|
||||||
},
|
},
|
||||||
onRedirectHome: () => {
|
onRedirectHome: () => {
|
||||||
dispatch(routerPush('/'));
|
dispatch(routerPush('/'));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user