Skip to content

Commit 491462f

Browse files
committed
improve and test connection failure logic
1 parent 8155c92 commit 491462f

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,6 @@ srh-*.tar
2929

3030
*.iml
3131

32-
srh-config/
32+
srh-config/
33+
34+
test-project/

lib/srh/http/command_handler.ex

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,20 @@ defmodule Srh.Http.CommandHandler do
7373
{:ok, result_map} ->
7474
[result_map | responses]
7575

76+
{:connection_error, result} ->
77+
{:connection_error, result}
78+
7679
{:redis_error, result} ->
7780
[result | responses]
7881
end
7982

80-
dispatch_command_array(rest, connection_info, updated_responses)
83+
case updated_responses do
84+
{:connection_error, result} ->
85+
{:connection_error, result}
86+
87+
_ ->
88+
dispatch_command_array(rest, connection_info, updated_responses)
89+
end
8190
end
8291

8392
defp dispatch_command_array([], _connection_info, responses) do
@@ -113,7 +122,7 @@ defmodule Srh.Http.CommandHandler do
113122
}
114123

115124
{:error, error} ->
116-
decode_error(error)
125+
decode_error(error, srh_id)
117126
end
118127

119128
Client.return_worker(client_pid, worker_pid)
@@ -122,7 +131,7 @@ defmodule Srh.Http.CommandHandler do
122131
result
123132

124133
{:error, error} ->
125-
decode_error(error)
134+
decode_error(error, srh_id)
126135
end
127136

128137
{:error, msg} ->
@@ -167,7 +176,7 @@ defmodule Srh.Http.CommandHandler do
167176
{:ok, %{result: res}}
168177

169178
{:error, error} ->
170-
decode_error(error)
179+
decode_error(error, srh_id)
171180
end
172181

173182
{:error, msg} ->
@@ -176,9 +185,13 @@ defmodule Srh.Http.CommandHandler do
176185
end
177186

178187
# Figure out if it's an actual Redis error or a Redix error
179-
defp decode_error(error) do
188+
defp decode_error(error, srh_id) do
180189
case error do
181190
%{reason: :closed} ->
191+
IO.puts(
192+
"WARNING: SRH was unable to connect to the Redis server. Please make sure it is running, and the connection information is correct. SRH ID: #{srh_id}"
193+
)
194+
182195
{
183196
:connection_error,
184197
"Unable to connect to the Redis server"

lib/srh/http/result_encoder.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ defmodule Srh.Http.ResultEncoder do
99
{:redis_error, error_result_map}
1010
end
1111

12+
def encode_response({:connection_error, error_result_map}) do
13+
{:connection_error, error_result_map}
14+
end
15+
1216
# List-based responses, they will contain multiple entries
1317
# It's important to note that this is DIFFERENT from a list of values,
1418
# as it's a list of separate command responses. Each is a map that either

0 commit comments

Comments
 (0)