camlspotter avatar camlspotter committed 7197bd2

Http error now has url

Comments (0)

Files changed (5)

     type t = Data.Branch.t mc_fields with conv(json, ocaml)
 
     let get ~accountname ~repo_slug = 
-      Format.eprintf "%s : %s...@." accountname repo_slug;
+      (* Format.eprintf "%s : %s...@." accountname repo_slug; *) (* CR jfuruse: LOG *)
       Json.curl_get_and_parse 
         t_of_json
         (fun h ->
 let ok200 = function
-  | 200, v -> `Ok v
-  | n, mes -> `Error (`Http (n, mes))
+  | _, 200, v -> `Ok v
+  | url, n, mes -> `Error (`Http (url, n, mes))
 
 let get_string f = 
   let h = new Curl.handle in
   h#set_writefunction (fun s -> Buffer.add_string buf s; String.length s);
   h#perform;
   let code = h#get_httpcode in
+  let url = h#get_effectiveurl in
   h#cleanup; (* Need to flush out cookies *)
-  ok200 (code, Buffer.contents buf)
+  ok200 (url, code, Buffer.contents buf)
 
 let download dst f =
   let h = new Curl.handle in
     output_string oc s; String.length s);
   h#perform;
   let code = h#get_httpcode in
+  let url = h#get_effectiveurl in
   h#cleanup; (* Need to flush out cookies *)
   close_out oc;
   match code with
   | 200 -> Unix.rename tmp dst; `Ok dst
-  | e -> `Error (`Http (e, tmp))
+  | e -> `Error (`Http (url, e, tmp))
   
-val ok200 : int * 'a -> [> `Ok of 'a | `Error of [> `Http of int * 'a ]]
+val ok200 : string * int * 'a -> [> `Ok of 'a | `Error of [> `Http of string * int * 'a ]]
 (** HTTP result to a result monad *)
 
-val get_string : (Curl.handle -> unit) -> [> `Error of [> `Http of int * string ] | `Ok of string ]
+val get_string : (Curl.handle -> unit) -> [> `Error of [> `Http of string * int * string ] | `Ok of string ]
 (** Get string *)
 
-val download : string -> (Curl.handle -> unit) -> [> `Error of [> `Http of int * string ] | `Ok of string ]
+val download : string -> (Curl.handle -> unit) -> [> `Error of [> `Http of string * int * string ] | `Ok of string ]
 (** Download file. Return the final downloaded file path.
     At error, the tmp file is not removed since it may contain error message. 
 *)
     | `Error e -> `Error (`Json_conv e)
 
   let format ppf = function
-    | `Http (n, _err) -> fprintf ppf "HTTP Error %d@." n
-    | `Json_parse exn -> fprintf ppf "Error at Json parse: %s@." (Printexc.to_string exn)
-    | `Other exn      -> fprintf ppf "Error: %s@." (Printexc.to_string exn)
+    | `Http (url, n, _err) -> fprintf ppf "HTTP Error %d (%s)" n url
+    | `Json_parse exn -> fprintf ppf "Error at Json parse: %s" (Printexc.to_string exn)
+    | `Other exn      -> fprintf ppf "Error: %s" (Printexc.to_string exn)
     | `Json_conv e -> Json_conv.format_full_error Format.stderr e 
 
   let from_Ok = function
     ->  ('a, [> `Json_conv of Json.t Meta_conv.Error.t]) Meta_conv.Result.t
 
   val format : Format.t 
-    -> [< `Http of int * 'a
+    -> [< `Http of string * int * 'a
        | `Json_conv of Json.t Meta_conv.Error.t
        | `Json_parse of exn
        | `Other of exn ] 
     -> unit
 
   val from_Ok :
-    [< `Error of [< `Http of int * 'a
+    [< `Error of [< `Http of string * int * 'a
                  | `Json_conv of Json.t Meta_conv.Error.t
                  | `Json_parse of exn
                  | `Other of exn ]
 val curl_get_and_parse :
   'a Json_conv.decoder 
   -> (Curl.handle -> unit) 
-  -> ('a, [> `Http of int * string
+  -> ('a, [> `Http of string * int * string
           | `Json_conv of Json.t Meta_conv.Error.t
           | `Json_parse of exn ]) Meta_conv.Result.t
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.