diff --git a/bin/main.ml b/bin/main.ml index e09b116..93dab77 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -2,8 +2,6 @@ open Pusk.Net open Pusk.Drivers open Pusk.Utils -exception Any of string - let start driver = let name_driver = prepare driver in let data_driver = run_process name_driver [] in diff --git a/lib/drivers.ml b/lib/drivers.ml index b87bb6e..5988b84 100644 --- a/lib/drivers.ml +++ b/lib/drivers.ml @@ -15,7 +15,7 @@ let rec download uri dest = let uri = Uri.of_string url in let redirect_url = Uri.resolve "" uri uri in download redirect_url dest - | None -> failwith "Redirect location not found") + | None -> raise (Any "Redirect location not found")) else if Cohttp.Code.is_success code then ( print_endline "Downloading..."; @@ -28,8 +28,8 @@ let rec download uri dest = print_endline "Download done!"; Lwt.return_unit) else - failwith - ("Failed to download file. HTTP status: " ^ Cohttp.Code.string_of_status status) + raise + (Any ("Failed to download file. HTTP status: " ^ Cohttp.Code.string_of_status status)) ;; let download_gecko_driver version output = diff --git a/lib/net.ml b/lib/net.ml index 7694378..e5082b8 100644 --- a/lib/net.ml +++ b/lib/net.ml @@ -37,10 +37,10 @@ let get_session () = let rec find_session_id = function | ("sessionId", `String session_id) :: _ -> session_id | _ :: rest -> find_session_id rest - | [] -> failwith "Session ID not found" + | [] -> raise (Any "Session ID not found") in find_session_id (Yojson.Safe.Util.to_assoc value) - | _ -> failwith "get_session | Invalid JSON" + | _ -> raise (Any "get_session | Invalid JSON") ;; let close_session id = execute_delete_request (driver id) = "{\"value\":null}" @@ -61,8 +61,8 @@ let rec wait_for_load session_id = then ( Unix.sleep 1; wait_for_load session_id) - | _ -> failwith "Error when waiting for page to load") - | _ -> failwith "wait_for_load | Invalid JSON" + | _ -> raise (Any "Error when waiting for page to load")) + | _ -> raise (Any "wait_for_load | Invalid JSON") ;; let navigate ?(wait = true) url session_id = diff --git a/lib/utils.ml b/lib/utils.ml index 0417f5e..104fe69 100644 --- a/lib/utils.ml +++ b/lib/utils.ml @@ -1,3 +1,5 @@ +exception Any of string + let fmt = Printf.sprintf let load_dotenv =