Skip to content

Commit 7a2b4c6

Browse files
authored
Merge pull request #468 from topcoderinc/issue-467
Issue 467
2 parents 88c5a03 + 5754c33 commit 7a2b4c6

File tree

6 files changed

+43
-40
lines changed

6 files changed

+43
-40
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: 3 additions & 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

@@ -75,6 +75,8 @@ export function reducer(state = initialState, action) {
7575
const i = getInstanceById(action.payload.id, state);
7676
i.status = 'failed';
7777
i.working = false;
78+
i.selected = false;
79+
i.expanded = false;
7880
return state;
7981
}
8082
case RedisActions.RedisConnect: {

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

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ 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+
import {MatDialog} from '@angular/material';
9+
10+
import {RedisConnectFailed} from '../ngrx/actions/redis-actions';
11+
import {CollapseCli} from '../ngrx/actions/cli-actions';
12+
import {REDIS_INSTANCES_KEY} from '../ngrx/reducer/redis-reducer';
13+
import {UtilService} from './util.service';
714

815
export const API_BASE_URL = environment.URI;
916

@@ -12,8 +19,12 @@ export const API_BASE_URL = environment.URI;
1219
})
1320

1421
export class HttpHelperService {
15-
constructor(private http: HttpClient) {
16-
}
22+
constructor(
23+
private http: HttpClient,
24+
private util: UtilService,
25+
private _store: Store<any>,
26+
private dialogService: MatDialog
27+
) { }
1728

1829
/**
1930
* Performs a request with `get` http method.
@@ -45,8 +56,26 @@ export class HttpHelperService {
4556
* catches the auth error
4657
* @param error the error response
4758
*/
48-
catchError(error: Response): Observable<Response> {
49-
return throwError(error);
59+
catchError(error: any): Observable<any> {
60+
const err = error.error;
61+
if (err.code === 500) {
62+
const instancesString = localStorage.getItem(REDIS_INSTANCES_KEY);
63+
const instances = instancesString ? JSON.parse(instancesString) : [];
64+
const instance = _.find(instances, {'id': err.instanceId});
65+
if (instance) {
66+
const id = instance.id;
67+
const host = instance.serverModel.name;
68+
const port = instance.serverModel.port;
69+
// reset UI if redis connection fails
70+
this.dialogService.closeAll();
71+
this.util.showMessage(`Failed to connect Redis server at ${host}:${port}.`);
72+
this._store.dispatch(new RedisConnectFailed({id}));
73+
this._store.dispatch(new CollapseCli());
74+
}
75+
return of();
76+
} else {
77+
return throwError(error);
78+
}
5079
}
5180

5281
/**

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