Skip to content

Commit 0ad0950

Browse files
committed
connection failed normalization
1 parent b0cd51e commit 0ad0950

File tree

6 files changed

+32
-39
lines changed

6 files changed

+32
-39
lines changed

lib/common/errors.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
* the base error class
1616
*/
1717
class AppError extends Error {
18-
constructor(instanceId, status, message) {
18+
constructor(instanceId, status, message, lineNo) {
1919
super();
2020

2121
this.instanceId = instanceId;
2222
this.status = status;
2323
this.message = message || 'unknown exception';
24-
this.lineNo = -1;
24+
this.lineNo = lineNo || -1;
2525
}
2626
}
2727

src/app/components/import-data-dialog/import-data-dialog.component.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class ImportDataDialogComponent implements OnInit {
1717
public instanceId = '';
1818

1919
public rawContent = '';
20-
public flushDB = true;
20+
public flushDB = false;
2121
public opType = '';
2222
public exportType = 'redis';
2323

@@ -114,18 +114,12 @@ export class ImportDataDialogComponent implements OnInit {
114114

115115
const totalRow = this.flushDB ? commands.length - 1 : commands.length;
116116
this.redisService.call(this.instanceId, commands).subscribe((rsp) => {
117-
let numberOfSucceed = 0;
118-
_.each(rsp, v => {
119-
numberOfSucceed += (!!v && v.toString().toLowerCase().indexOf('err') < 0) ? 1 : 0;
120-
});
121-
numberOfSucceed -= this.flushDB ? 1 : 0;
122-
const numberOfFailed = totalRow - numberOfSucceed;
123-
this.util.showMessage(`${numberOfSucceed} row${numberOfSucceed !== 1 ? 's were' : ' was'} imported
124-
successfully, ${numberOfFailed} row${numberOfFailed !== 1 ? 's have' : ' has'} failed.`);
117+
this.util.showMessage(`All rows were imported successfully.`);
125118
this.dialogRef.close();
126119
this._store.dispatch(new ReqFetchTree({id: this.instanceId}));
127120
}, err => {
128-
this.util.showMessage('Failed to import commands: ' + this.util.getErrorMessage(err));
121+
const errorLineNo = err.error.line - (this.flushDB ? 1 : 0);
122+
this.util.showMessage(`The command on row ${errorLineNo} failed with error: ${this.util.getErrorMessage(err)}`);
129123
});
130124
}
131125
}

src/app/ngrx/effects/page-effect.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {RedisService} from '../../services/redis.service';
77

88

99
import {PageActions, LoadedPage, ReqLoadRootPage} from '../actions/page-actions';
10-
import {RedisConnectFailed} from '../actions/redis-actions';
1110

1211
import {catchError, map, mergeMap} from 'rxjs/operators';
1312
import {Injectable} from '@angular/core';
@@ -54,10 +53,6 @@ export class PageEffect {
5453
requestId: action['payload'].requestId,
5554
id: action['payload'].id
5655
});
57-
}),
58-
catchError(() => {
59-
const id = action['payload'].id;
60-
return of( new RedisConnectFailed({id}));
6156
})
6257
);
6358
}

src/app/ngrx/effects/redis-effect.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {of, Observable} from 'rxjs';
77
import {RedisService} from '../../services/redis.service';
88

99

10-
import {RedisActions, FetchedTree, RedisConnect, RedisConnectFailed, ReqFetchTree, ReqRedisConnect} from '../actions/redis-actions';
10+
import {RedisActions, FetchedTree, RedisConnect, ReqFetchTree, ReqRedisConnect} from '../actions/redis-actions';
1111
import {catchError, map, mergeMap} from 'rxjs/operators';
1212
import {Injectable} from '@angular/core';
1313
import {Action} from '@ngrx/store';
@@ -24,7 +24,6 @@ export class RedisEffect {
2424
/**
2525
* send connect request to backend when dispatch "ReqRedisConnect"
2626
* and when backend returned, dispatch data to "RedisConnect"
27-
* when backend return error, dispatch to "RedisConnectFailed"
2827
*/
2928
@Effect()
3029
connectRedis: Observable<Action> = this.actions$.pipe(
@@ -36,18 +35,6 @@ export class RedisEffect {
3635
action['payload'].scb(data);
3736
}
3837
return new RedisConnect(data);
39-
}),
40-
catchError(() => {
41-
if (action['payload'].fcb) {
42-
action['payload'].fcb(action['payload'].instance);
43-
}
44-
if (action['payload'].instance) {
45-
const id = action['payload'].instance.id;
46-
const host = action['payload'].instance.serverModel.name;
47-
const port = action['payload'].instance.serverModel.port;
48-
this.util.showMessage(`Fail to connect Redis server at ${host}:${port}.`);
49-
return of(new RedisConnectFailed({id}));
50-
}
5138
})
5239
);
5340
}
@@ -57,7 +44,6 @@ export class RedisEffect {
5744
/**
5845
* send fetch tree request to backend when dispatch "ReqFetchTree"
5946
* and when backend returned, dispatch data to "FetchedTree"
60-
* when backend return error, dispatch to "RedisConnectFailed"
6147
*/
6248
@Effect()
6349
fetchTree: Observable<Action> = this.actions$.pipe(
@@ -70,9 +56,6 @@ export class RedisEffect {
7056
action['payload'].scb(data);
7157
}
7258
return new FetchedTree({id, data});
73-
}),
74-
catchError(() => {
75-
return of( new RedisConnectFailed({id}));
7659
})
7760
);
7861
}

src/app/ngrx/reducer/redis-reducer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {RedisActions} from '../actions/redis-actions';
66
import {RedisInstance} from '../../models/redis-instance';
77
import _ from 'lodash';
88

9-
const REDIS_INSTANCES_KEY = 'REDIS_INSTANCES_KEY';
9+
export const REDIS_INSTANCES_KEY = 'REDIS_INSTANCES_KEY';
1010
const defaultState = [{serverModel: {name: 'default-local', ip: 'localhost', port: 6379, db: 0, password: ''}, id: uuid()}];
1111
let initState = defaultState;
1212

src/app/services/http-helper.service.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import {HttpClient, HttpHeaders} from '@angular/common/http';
44
import * as _ from 'lodash';
55
import {environment} from '../../environments/environment';
66
import {catchError, delay} from 'rxjs/operators';
7+
import {Store} from '@ngrx/store';
8+
9+
import {RedisConnectFailed} from '../ngrx/actions/redis-actions';
10+
import {REDIS_INSTANCES_KEY} from '../ngrx/reducer/redis-reducer';
11+
import {UtilService} from './util.service';
712

813
export const API_BASE_URL = environment.URI;
914

@@ -12,8 +17,11 @@ export const API_BASE_URL = environment.URI;
1217
})
1318

1419
export class HttpHelperService {
15-
constructor(private http: HttpClient) {
16-
}
20+
constructor(
21+
private http: HttpClient,
22+
private util: UtilService,
23+
private _store: Store<any>
24+
) { }
1725

1826
/**
1927
* Performs a request with `get` http method.
@@ -45,7 +53,20 @@ export class HttpHelperService {
4553
* catches the auth error
4654
* @param error the error response
4755
*/
48-
catchError(error: Response): Observable<Response> {
56+
catchError(error: any): Observable<any> {
57+
const err = error.error;
58+
if (err.code === 500) {
59+
const instancesString = localStorage.getItem(REDIS_INSTANCES_KEY);
60+
const instances = instancesString ? JSON.parse(instancesString) : [];
61+
const instance = _.find(instances, {'id': err.instanceId});console.log('dsadas');console.log(instance);
62+
if (instance) {
63+
const id = instance.id;
64+
const host = instance.serverModel.name;
65+
const port = instance.serverModel.port;
66+
this.util.showMessage(`Fail to connect Redis server at ${host}:${port}.`);
67+
this._store.dispatch(new RedisConnectFailed({id}));
68+
}
69+
}
4970
return throwError(error);
5071
}
5172

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy