@@ -8,6 +8,7 @@ defmodule Srh.Http.CommandHandler do
88 case RequestValidator . validate_redis_body ( conn . body_params ) do
99 { :ok , command_array } ->
1010 do_handle_command ( command_array , token )
11+
1112 { :error , error_message } ->
1213 { :malformed_data , error_message }
1314 end
@@ -17,6 +18,7 @@ defmodule Srh.Http.CommandHandler do
1718 case RequestValidator . validate_pipeline_redis_body ( conn . body_params ) do
1819 { :ok , array_of_command_arrays } ->
1920 do_handle_command_array ( array_of_command_arrays , token )
21+
2022 { :error , error_message } ->
2123 { :malformed_data , error_message }
2224 end
@@ -26,28 +28,34 @@ defmodule Srh.Http.CommandHandler do
2628 case TokenResolver . resolve ( token ) do
2729 { :ok , connection_info } ->
2830 dispatch_command ( command_array , connection_info )
29- { :error , msg } -> { :not_authorized , msg }
31+
32+ { :error , msg } ->
33+ { :not_authorized , msg }
3034 end
3135 end
3236
3337 defp do_handle_command_array ( array_of_command_arrays , token ) do
3438 case TokenResolver . resolve ( token ) do
3539 { :ok , connection_info } ->
3640 dispatch_command_array ( array_of_command_arrays , connection_info )
37- { :error , msg } -> { :not_authorized , msg }
41+
42+ { :error , msg } ->
43+ { :not_authorized , msg }
3844 end
3945 end
4046
4147 defp dispatch_command_array ( _arr , _connection_info , responses \\ [ ] )
42-
48+
4349 defp dispatch_command_array ( [ current | rest ] , connection_info , responses ) do
44- updated_responses = case dispatch_command ( current , connection_info ) do
45- { :ok , result_map } ->
46- [ result_map | responses ]
47- { :malformed_data , result_json } ->
48- # TODO: change up the chain to json this at the last moment, so this isn't here
49- [ Jason . decode! ( result_json ) | responses ]
50- end
50+ updated_responses =
51+ case dispatch_command ( current , connection_info ) do
52+ { :ok , result_map } ->
53+ [ result_map | responses ]
54+
55+ { :malformed_data , result_json } ->
56+ # TODO: change up the chain to json this at the last moment, so this isn't here
57+ [ Jason . decode! ( result_json ) | responses ]
58+ end
5159
5260 dispatch_command_array ( rest , connection_info , updated_responses )
5361 end
@@ -57,7 +65,10 @@ defmodule Srh.Http.CommandHandler do
5765 { :ok , Enum . reverse ( responses ) }
5866 end
5967
60- defp dispatch_command ( command_array , % { "srh_id" => srh_id , "max_connections" => max_connections } = connection_info )
68+ defp dispatch_command (
69+ command_array ,
70+ % { "srh_id" => srh_id , "max_connections" => max_connections } = connection_info
71+ )
6172 when is_number ( max_connections ) do
6273 case GenRegistry . lookup_or_start ( Client , srh_id , [ max_connections , connection_info ] ) do
6374 { :ok , pid } ->
@@ -66,16 +77,16 @@ defmodule Srh.Http.CommandHandler do
6677 |> ClientWorker . redis_command ( command_array ) do
6778 { :ok , res } ->
6879 { :ok , % { result: res } }
80+
6981 { :error , error } ->
7082 {
7183 :malformed_data ,
72- Jason . encode! (
73- % {
74- error: error . message
75- }
76- )
84+ Jason . encode! ( % {
85+ error: error . message
86+ } )
7787 }
7888 end
89+
7990 { :error , msg } ->
8091 { :server_error , msg }
8192 end
0 commit comments