WebSocket Error handling

This commit is contained in:
crusader 2017-08-14 19:06:38 +09:00
parent 7f404448ec
commit 58b1823b83
4 changed files with 26 additions and 8 deletions

View File

@ -1,4 +1,5 @@
import {
ErrorCode,
Notification,
Request,
Response,
@ -30,6 +31,11 @@ enum WebSocketReadyState {
CLOSED = 3,
}
export interface RuntimeError {
type: string;
data?: any;
}
export default class WebSocketRPC {
private url: string;
private connStatus: WebSocketStatus;
@ -145,7 +151,14 @@ export default class WebSocketRPC {
console.log(result);
promise.resolve(result);
} 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 {
console.log('??????');
}

View File

@ -1,4 +1,5 @@
export const enum ErrorCode {
E_RUNTIME = -33000,
E_PARSE = -32700,
E_INVALID_REQ = -32600,
E_NO_METHOD = -32601,
@ -40,8 +41,12 @@ export class ProtocolError {
return this.data;
}
public static newError(json: string): ProtocolError {
return JSON.parse(json);
public static convert(error: ProtocolError): ProtocolError {
const code = error.code;
if (undefined === code) {
throw new Error(`Error must include Code`);
}
return new ProtocolError(code, error.message, error.data);
}
}

View File

@ -43,7 +43,7 @@ export class Response<ID> extends Header {
let res = new Response(id);
res.Protocol = response.protocol;
res.result = response.result;
res.error = response.error;
res.error = ProtocolError.convert(response.error);
return res;
}

View File

@ -20,7 +20,7 @@ export function mapDispatchToProps(dispatch: Dispatch<any>, ownProps?: any): Sig
return {
onSignIn: (signinId: string, signinPw: string) => {
// dispatch(signinActions.request(signinId, signinPw));
dispatch(asyncRequestActions.request('MemberService', 'signin', signinActions.REQUEST, signinId, signinPw));
dispatch(asyncRequestActions.request('MemberService1', 'signin', signinActions.REQUEST, signinId, signinPw));
},
onRedirectHome: () => {
dispatch(routerPush('/'));