Skip to content

coinprices/PriceFetchError.hpp

Namespaces

Name
outcome
sgns

Classes

Name
struct sgns::PriceFetchFailure
Struct error carrier: a code plus the HTTP status that produced it, so tests and logs assert the numeric status without string-matching.

Types

Name
enum class PriceFetchError { EmptyInput = 1, NetworkError, JsonParseError, NoDataFound, RateLimitExceeded, DateTooOld, HttpStatus, Blocked}
Typed price-fetch error taxonomy (D-15).
template <typename T >
using boost::outcome_v2::basic_result< T, PriceFetchFailure, boost::outcome_v2::policy::terminate >
PriceResult
result alias carrying the status-bearing failure type.

Types Documentation

enum PriceFetchError

Enumerator Value Description
EmptyInput 1
NetworkError
JsonParseError
NoDataFound
RateLimitExceeded
DateTooOld
HttpStatus
Blocked

Typed price-fetch error taxonomy (D-15).

The first six values keep the legacy price-error names and ordering so log/test vocabulary stayed stable across the Phase 4 cutover (the legacy carrier class was deleted in its entirety per Phase 4 D-09); HttpStatus and Blocked are new.

using PriceResult

template <typename T >
using sgns::PriceResult = typedef boost::outcome_v2::basic_result<T, PriceFetchFailure, boost::outcome_v2::policy::terminate>;

result alias carrying the status-bearing failure type.

The terminate policy is required for a non-error_code error type (boost::outcome's default_policy assumes std::error_code and drags in exception_ptr machinery that cannot convert). Observers used here (bool/operator*/error) are policy-safe.

Source code

#pragma once

#include <HTTPTypes.hpp>

#include <fmt/format.h>
#include <libp2p/outcome/outcome.hpp>

#include <optional>
#include <string>
#include <utility>

namespace outcome
{
    using libp2p::outcome::failure;
    using libp2p::outcome::result;
    using libp2p::outcome::success;
}

namespace sgns
{
    enum class PriceFetchError
    {
        EmptyInput       = 1,
        NetworkError,   // legacy slot 2 — transport-class failures map here
        JsonParseError, // legacy slot 3
        NoDataFound,    // legacy slot 4
        RateLimitExceeded, // legacy slot 5
        DateTooOld,     // legacy slot 6
        HttpStatus,     // new: any non-200 status other than 403/429
        Blocked,        // new: 403 WAF block (CloudFront-style)
    };

    struct PriceFetchFailure
    {
        PriceFetchError code       = PriceFetchError::NetworkError;
        unsigned        httpStatus = 0;

        std::optional<http::ClientError> transportError;

        std::string Message() const
        {
            switch ( code )
            {
                case PriceFetchError::EmptyInput:
                    return "Empty Input";
                case PriceFetchError::NetworkError:
                    return httpStatus != 0 ? fmt::format( "Network Error: HTTP {}", httpStatus )
                                           : std::string( "Network Error" );
                case PriceFetchError::JsonParseError:
                    return httpStatus != 0 ? fmt::format( "JSON parse error: HTTP {}", httpStatus )
                                           : std::string( "JSON parse error" );
                case PriceFetchError::NoDataFound:
                    return "No data found";
                case PriceFetchError::RateLimitExceeded:
                    return httpStatus != 0 ? fmt::format( "rate limit exceeded: HTTP {}", httpStatus )
                                           : std::string( "Rate limit exceeded" );
                case PriceFetchError::DateTooOld:
                    return "Date exceeds year limit";
                case PriceFetchError::HttpStatus:
                    return fmt::format( "HTTP {}", httpStatus );
                case PriceFetchError::Blocked:
                    return fmt::format( "price fetch blocked: HTTP {}", httpStatus );
            }
            return "Unknown error";
        }
    };

    template <typename T>
    using PriceResult =
        boost::outcome_v2::basic_result<T, PriceFetchFailure, boost::outcome_v2::policy::terminate>;
} // namespace sgns

Updated on 2026-10-09 at 04:02:50 +0000