package polymarket

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Polymarket_common.ErrorSource

Polymorphic error types for composable error handling.

This module provides extensible error types using polymorphic variants, allowing different parts of the codebase to define their own error cases while maintaining composability.

Base Error Types

Sourcetype http_error = {
  1. status : int;
  2. body : string;
  3. message : string;
}

HTTP-related errors.

Sourcetype parse_error = {
  1. context : string;
  2. message : string;
}

JSON parsing errors.

Sourcetype network_error = {
  1. message : string;
}

Network/connection errors.

Sourcetype rate_limit_error = {
  1. retry_after : float;
  2. route_key : string;
}

Rate limiting errors.

Polymorphic Error Variants

Sourcetype http_errors = [
  1. | `Http_error of http_error
  2. | `Parse_error of parse_error
  3. | `Network_error of network_error
]

Core HTTP client errors.

Sourcetype rate_limit_errors = [
  1. | `Rate_limited of rate_limit_error
]

Rate limiting errors.

Sourcetype api_errors = [
  1. | http_errors
  2. | rate_limit_errors
]

All API errors (HTTP + rate limiting).

Error Constructors

Sourceval http_error : status:int -> body:string -> message:string -> [> `Http_error of http_error ]

Construct an HTTP error.

Sourceval parse_error : context:string -> message:string -> [> `Parse_error of parse_error ]

Construct a parse error.

Sourceval network_error : message:string -> [> `Network_error of network_error ]

Construct a network error.

Sourceval rate_limited : retry_after:float -> route_key:string -> [> `Rate_limited of rate_limit_error ]

Construct a rate limit error.

Error Formatting

Sourceval http_error_to_string : http_error -> string
Sourceval parse_error_to_string : parse_error -> string
Sourceval network_error_to_string : network_error -> string
Sourceval rate_limit_error_to_string : rate_limit_error -> string
Sourceval http_errors_to_string : http_errors -> string

Convert HTTP errors to string.

Sourceval api_errors_to_string : api_errors -> string

Convert API errors (including rate limiting) to string.

Pretty Printers

Sourceval pp_http_errors : Format.formatter -> http_errors -> unit
Sourceval pp_api_errors : Format.formatter -> api_errors -> unit

Error Parsing Helpers

Sourceval parse_http_error : status:int -> string -> [> `Http_error of http_error ]

Parse an HTTP error response body to extract error message.

Result Helpers

Sourceval map_error : ('a -> 'b) -> ('c, 'a) result -> ('c, 'b) result

Map over the error type of a result.

Sourceval lift_http_error : ('a, http_errors) result -> ('a, api_errors) result

Lift an http_errors result to an api_errors result.