You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-04 15:02:09 +03:00
chore: refactor flush and error
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
'use strict'
|
||||
|
||||
const Errors = require('redis-errors')
|
||||
const debug = require('./debug')
|
||||
var lazyConnect = function (client) {
|
||||
lazyConnect = require('./connect')
|
||||
@@ -63,13 +64,10 @@ function reconnect (client, why, error) {
|
||||
|
||||
if (why === 'timeout') {
|
||||
var message = 'Redis connection in broken state: connection timeout exceeded.'
|
||||
const err = new Error(message)
|
||||
const err = new Errors.RedisError(message)
|
||||
// TODO: Find better error codes...
|
||||
err.code = 'CONNECTION_BROKEN'
|
||||
client.flushAndError({
|
||||
message: message,
|
||||
code: 'CONNECTION_BROKEN'
|
||||
})
|
||||
client.flushAndError(message, 'CONNECTION_BROKEN')
|
||||
client.emit('error', err)
|
||||
client.end(false)
|
||||
return
|
||||
@@ -78,10 +76,7 @@ function reconnect (client, why, error) {
|
||||
// If client is a requested shutdown, then don't retry
|
||||
if (client.closing) {
|
||||
debug('Connection ended by quit / end command, not retrying.')
|
||||
client.flushAndError({
|
||||
message: 'Stream connection ended and command aborted.',
|
||||
code: 'NR_CLOSED'
|
||||
}, {
|
||||
client.flushAndError('Stream connection ended and command aborted.', 'NR_CLOSED', {
|
||||
error
|
||||
})
|
||||
return
|
||||
@@ -98,10 +93,7 @@ function reconnect (client, why, error) {
|
||||
if (client.retryDelay instanceof Error) {
|
||||
error = client.retryDelay
|
||||
}
|
||||
client.flushAndError({
|
||||
message: 'Stream connection ended and command aborted.',
|
||||
code: 'NR_CLOSED'
|
||||
}, {
|
||||
client.flushAndError('Stream connection ended and command aborted.', 'NR_CLOSED', {
|
||||
error
|
||||
})
|
||||
// TODO: Check if client is so smart
|
||||
@@ -117,10 +109,7 @@ function reconnect (client, why, error) {
|
||||
client.offlineQueue.unshift.apply(client.offlineQueue, client.commandQueue.toArray())
|
||||
client.commandQueue.clear()
|
||||
} else if (client.commandQueue.length !== 0) {
|
||||
client.flushAndError({
|
||||
message: 'Redis connection lost and command aborted.',
|
||||
code: 'UNCERTAIN_STATE'
|
||||
}, {
|
||||
client.flushAndError('Redis connection lost and command aborted.', 'UNCERTAIN_STATE', {
|
||||
error,
|
||||
queues: ['commandQueue']
|
||||
})
|
||||
|
Reference in New Issue
Block a user