My agentic slop goes here. Not intended for anyone else!
at main 3.5 kB view raw
1(** Centralized error handling for the Requests library *) 2 3(** Log source for error reporting *) 4val src : Logs.Src.t 5 6(** {1 Exception Types} *) 7 8(** Raised when a request times out *) 9exception Timeout 10 11(** Raised when too many redirects are encountered *) 12exception TooManyRedirects of { url: string; count: int; max: int } 13 14(** Raised when a connection error occurs *) 15exception ConnectionError of string 16 17(** Raised when an HTTP error response is received *) 18exception HTTPError of { 19 url: string; 20 status: int; 21 reason: string; 22 body: string option; 23 headers: Headers.t 24} 25 26(** Raised when authentication fails *) 27exception AuthenticationError of string 28 29(** Raised when there's an SSL/TLS error *) 30exception SSLError of string 31 32(** Raised when proxy connection fails *) 33exception ProxyError of string 34 35(** Raised when content encoding/decoding fails *) 36exception EncodingError of string 37 38(** Raised when an invalid URL is provided *) 39exception InvalidURL of string 40 41(** Raised when request is invalid *) 42exception InvalidRequest of string 43 44(** {1 Error Type} *) 45 46(** Unified error type for result-based error handling *) 47type t = [ 48 | `Timeout 49 | `TooManyRedirects of string * int * int (* url, count, max *) 50 | `ConnectionError of string 51 | `HTTPError of string * int * string * string option * Headers.t (* url, status, reason, body, headers *) 52 | `AuthenticationError of string 53 | `SSLError of string 54 | `ProxyError of string 55 | `EncodingError of string 56 | `InvalidURL of string 57 | `InvalidRequest of string 58 | `UnknownError of string 59] 60 61(** {1 Conversion Functions} *) 62 63(** Convert an exception to an error type *) 64val of_exn : exn -> t option 65 66(** Convert an error type to an exception *) 67val to_exn : t -> exn 68 69(** Raise an error as an exception *) 70val raise : t -> 'a 71 72(** {1 Combinators} *) 73 74(** Wrap a function that may raise exceptions into a result type *) 75val catch : (unit -> 'a) -> ('a, t) result 76 77(** Wrap an async function that may raise exceptions *) 78val catch_async : (unit -> 'a) -> ('a, t) result 79 80(** Map over the success case of a result *) 81val map : ('a -> 'b) -> ('a, t) result -> ('b, t) result 82 83(** Bind for result types with error *) 84val bind : ('a -> ('b, t) result) -> ('a, t) result -> ('b, t) result 85 86(** Applicative operator for combining results *) 87val both : ('a, t) result -> ('b, t) result -> ('a * 'b, t) result 88 89(** Get value or raise the error *) 90val get_exn : ('a, t) result -> 'a 91 92(** Get value or use default *) 93val get_or : default:'a -> ('a, t) result -> 'a 94 95(** Check if error is retryable *) 96val is_retryable : t -> bool 97 98(** Check if error is a client error (4xx) *) 99val is_client_error : t -> bool 100 101(** Check if error is a server error (5xx) *) 102val is_server_error : t -> bool 103 104(** {1 Pretty Printing} *) 105 106(** Pretty printer for errors *) 107val pp : Format.formatter -> t -> unit 108 109(** Pretty printer for exceptions (falls back to Printexc if not a known exception) *) 110val pp_exn : Format.formatter -> exn -> unit 111 112(** Convert error to string *) 113val to_string : t -> string 114 115(** {1 Syntax Module} *) 116 117(** Syntax module for let-operators *) 118module Syntax : sig 119 (** Bind operator for result types *) 120 val ( let* ) : ('a, t) result -> ('a -> ('b, t) result) -> ('b, t) result 121 122 (** Map operator for result types *) 123 val ( let+ ) : ('a, t) result -> ('a -> 'b) -> ('b, t) result 124 125 (** Both operator for combining results *) 126 val ( and* ) : ('a, t) result -> ('b, t) result -> ('a * 'b, t) result 127end