summaryrefslogtreecommitdiff
path: root/src/vyconfd.ml
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2018-05-22 21:04:11 +0700
committerDaniil Baturin <daniil@baturin.org>2018-05-22 21:04:11 +0700
commit08cc3adf5a85d1fd93ae9789e7fd1b1348095264 (patch)
tree3c449f91559250dc476ea452ffd4fbe47b65cb6c /src/vyconfd.ml
parent34184f16afd49f391d196dfa41ed23e64c8c20cf (diff)
downloadvyconf-08cc3adf5a85d1fd93ae9789e7fd1b1348095264.tar.gz
vyconf-08cc3adf5a85d1fd93ae9789e7fd1b1348095264.zip
Send a response to the client if error occurs.
Diffstat (limited to 'src/vyconfd.ml')
-rw-r--r--src/vyconfd.ml18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/vyconfd.ml b/src/vyconfd.ml
index 810a355..1260544 100644
--- a/src/vyconfd.ml
+++ b/src/vyconfd.ml
@@ -128,10 +128,17 @@ let list_children world token (req: request_list_children) =
let show_config world token (req: request_show_config) =
try
let fmt = BatOption.default Curly req.format in
+ print_endline (Util.string_of_list req.path);
let conf_str = Session.show_config world (find_session token) req.path fmt in
{response_tmpl with output=(Some conf_str)}
with Session.Session_error msg -> {response_tmpl with status=Fail; error=(Some msg)}
+let send_response oc resp =
+ let enc = Pbrt.Encoder.create () in
+ let%lwt () = encode_response resp enc |> return in
+ let%lwt resp_msg = Pbrt.Encoder.to_bytes enc |> return in
+ let%lwt () = Message.write oc resp_msg in
+ Lwt.return ()
let rec handle_connection world ic oc fd () =
try%lwt
@@ -162,13 +169,13 @@ let rec handle_connection world ic oc fd () =
| _ -> failwith "Unimplemented"
end) |> Lwt.return
in
- let enc = Pbrt.Encoder.create () in
- let%lwt () = encode_response resp enc |> return in
- let%lwt resp_msg = Pbrt.Encoder.to_bytes enc |> return in
- let%lwt () = Message.write oc resp_msg in
+ let%lwt () = send_response oc resp in
handle_connection world ic oc fd ()
with
- | Failure e -> Lwt_log.error e >>= handle_connection world ic oc fd
+ | Failure e ->
+ let%lwt () = Lwt_log.error e in
+ let%lwt () = send_response oc ({response_tmpl with status=Fail; error=(Some e)}) in
+ handle_connection world ic oc fd ()
| End_of_file -> Lwt_log.info "Connection closed" >>= return
let accept_connection world conn =
@@ -212,4 +219,5 @@ let () =
(FP.concat vc.config_dir vc.primary_config)
(FP.concat vc.config_dir vc.fallback_config) in
let world = Session.{world with running_config=config} in
+ let () = print_endline (Config_tree.render world.running_config) in
Lwt_main.run @@ main_loop !basepath world ()