Skip to content

Commit 19e8af5

Browse files
author
stand4love@163.com
committed
updated backend
1 parent d2500e7 commit 19e8af5

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

lib/common/errors.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,18 @@
1515
* the base error class
1616
*/
1717
class AppError extends Error {
18-
constructor(redis, status, message) {
18+
constructor(instanceId, status, message) {
1919
super();
20-
this.redis = redis || {};
21-
delete this.redis.password;
2220

21+
this.instanceId = instanceId;
2322
this.status = status;
2423
this.message = message || 'unknown exception';
2524
this.lineNo = -1;
2625
}
2726
}
2827

2928
module.exports = {
30-
newConnectTimeoutError: (redis, msg) => new AppError(redis, 500, msg || 'ConnectTimeout'),
31-
newConnectFailedError: (redis, msg) => new AppError(redis, 500, msg || 'ConnectFailed'),
32-
newReplyError: (redis, msg, lineNo = -1) => new AppError(redis, 400, msg, lineNo),
29+
newConnectTimeoutError: (instanceId, msg) => new AppError(instanceId, 500, msg || 'ConnectTimeout'),
30+
newConnectFailedError: (instanceId, msg) => new AppError(instanceId, 500, msg || 'ConnectFailed'),
31+
newReplyError: (instanceId, msg, lineNo = -1) => new AppError(instanceId, 400, msg, lineNo),
3332
};

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ module.exports = {
3939
result = await handler.method(req, h);
4040
} catch (e) {
4141
logger.error(e);
42-
result = {code: e.status, redis: e.redis, message: e.message, line: e.lineNo || -1}
42+
result = {code: e.status, instanceId: e.instanceId, message: e.message, line: e.lineNo || -1}
4343
status = e.status || 500;
4444
}
4545
return injectHeader(h.response(result).code(status));

lib/redis.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,22 @@ async function connect(body) {
3030
host: body.serverModel.ip, port: body.serverModel.port, db: body.serverModel.db,
3131
password: body.serverModel.password,
3232
showFriendlyErrorStack: true,
33-
maxRetriesPerRequest: 10,
3433
});
35-
36-
body.serverModel.id = body.id;
3734

3835
const timeoutHandler = setTimeout(() => {
3936
redis.disconnect();
40-
reject(errors.newConnectTimeoutError(body.serverModel));
37+
reject(errors.newConnectTimeoutError(body.id));
4138
}, 3 * 1000);
4239

4340
redis.on('error', (e) => {
4441
console.error(e);
4542
body.status = DISCONNECTED;
4643
});
4744

45+
redis.on('end', () => {
46+
redisInstanceCache[body.id] = null;
47+
});
48+
4849
redis.on('ready', () => {
4950
body.redis = redis;
5051
body.status = CONNECTED;
@@ -63,8 +64,8 @@ async function connect(body) {
6364
*/
6465
function getRedisConnection(query) {
6566
const redisConn = redisInstanceCache[query.id];
66-
if (!redisConn && redisConn.status !== CONNECTED) {
67-
throw errors.newConnectFailedError(redisConn ? redisConn.serverModel : {});
67+
if (!redisConn || redisConn.status !== CONNECTED) {
68+
throw errors.newConnectFailedError(query.id);
6869
}
6970
return redisConn;
7071
}
@@ -100,7 +101,7 @@ async function fetchTree(query) {
100101
}
101102
}
102103
} catch (e) {
103-
throw errors.newReplyError(redisConn.serverModel, e.message);
104+
throw errors.newReplyError(query.id, e.message);
104105
}
105106

106107
const tree = {};
@@ -183,7 +184,7 @@ async function call(query, body) {
183184
try {
184185
results.push(await redis.call(...lines[i]));
185186
} catch (e) {
186-
throw errors.newReplyError(redisConn.serverModel, e.message, i + 1);
187+
throw errors.newReplyError(query.id, e.message, i + 1);
187188
}
188189
}
189190
return results;
@@ -201,7 +202,7 @@ async function dump(query) {
201202
try {
202203
return await redisDump(query.exportType, redis);
203204
} catch (e) {
204-
throw errors.newReplyError(redisConn.serverModel, e.message);
205+
throw errors.newReplyError(query.id, e.message);
205206
}
206207
}
207208

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