Skip to content

Commit 3b4025c

Browse files
committed
CA-406770: Improve error message
1. WLB request will raise `wlb_authentication_failed` when catching `Http_client.Http_error`. But actually only error code 401 and 403 should raise this type exception. For other error code, raise `wlb_connection_reset`. Also print the detail error code and message. 2. `message_forwarding` raises same error for `Http_request_rejected` and `Connection_reset` so we don't know which exception actually be raised. Print detailed logs for these 2 exceptions. Signed-off-by: Bengang Yuan <[email protected]>
1 parent 2c6912a commit 3b4025c

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

ocaml/xapi/message_forwarding.ml

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -143,24 +143,15 @@ let do_op_on_common ~local_fn ~__context ~host ~remote_fn f =
143143
let task_opt = set_forwarding_on_task ~__context ~host in
144144
f __context host task_opt remote_fn
145145
with
146-
| Xmlrpc_client.Connection_reset | Http_client.Http_request_rejected _ ->
147-
warn
148-
"Caught Connection_reset when contacting host %s; converting into \
149-
CANNOT_CONTACT_HOST"
150-
(Ref.string_of host) ;
151-
raise
152-
(Api_errors.Server_error
153-
(Api_errors.cannot_contact_host, [Ref.string_of host])
154-
)
155-
| Xmlrpc_client.Stunnel_connection_failed ->
156-
warn
157-
"Caught Stunnel_connection_failed while contacting host %s; converting \
158-
into CANNOT_CONTACT_HOST"
159-
(Ref.string_of host) ;
160-
raise
161-
(Api_errors.Server_error
162-
(Api_errors.cannot_contact_host, [Ref.string_of host])
163-
)
146+
| ( Xmlrpc_client.Connection_reset
147+
| Http_client.Http_request_rejected _
148+
| Xmlrpc_client.Stunnel_connection_failed ) as e
149+
->
150+
error
151+
"%s: Caught %s when contacting host %s; converting into \
152+
CANNOT_CONTACT_HOST"
153+
__FUNCTION__ (Printexc.to_string e) (Ref.string_of host) ;
154+
raise Api_errors.(Server_error (cannot_contact_host, [Ref.string_of host]))
164155

165156
(* regular forwarding fn, with session and live-check. Used by most calls, will
166157
use the connection cache. *)

ocaml/xapi/workload_balancing.ml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,15 @@ let wlb_request ~__context ~host ~port ~auth ~meth ~params ~handler ~enable_log
329329
with
330330
| Remote_requests.Timed_out ->
331331
raise_timeout timeout
332-
| Http_client.Http_request_rejected _ | Http_client.Http_error _ ->
333-
raise_authentication_failed ()
332+
| Http_client.Http_error (code, msg) as e -> (
333+
error "%s: Caught %s when contacting WLB" __FUNCTION__
334+
(Printexc.to_string e) ;
335+
match code with
336+
| "401" | "403" ->
337+
raise_authentication_failed ()
338+
| _ ->
339+
raise_connection_reset ()
340+
)
334341
| Xmlrpc_client.Connection_reset ->
335342
raise_connection_reset ()
336343
| Stunnel.Stunnel_verify_error reason ->

0 commit comments

Comments
 (0)