kalshi-cpp 0.6.2
C++23 client for Kalshi's Predictions API
Loading...
Searching...
No Matches
error.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <expected>
5#include <string>
6#include <string_view>
7
8namespace kalshi {
9
22
23struct Error {
25 std::string message;
29 std::string api_code;
30
31 [[nodiscard]] static Error network(std::string msg) {
32 return {ErrorCode::NetworkError, std::move(msg), 0, {}};
33 }
34
35 [[nodiscard]] static Error auth(std::string msg) {
36 return {ErrorCode::AuthenticationError, std::move(msg), 0, {}};
37 }
38
39 [[nodiscard]] static Error parse(std::string msg) {
40 return {ErrorCode::ParseError, std::move(msg), 0, {}};
41 }
42
43 [[nodiscard]] static Error signing(std::string msg) {
44 return {ErrorCode::SigningError, std::move(msg), 0, {}};
45 }
46};
47
49template <typename T>
50using Result = std::expected<T, Error>;
51
52} // namespace kalshi
Definition api.hpp:15
std::expected< T, Error > Result
Result type for SDK operations.
Definition error.hpp:50
ErrorCode
Definition error.hpp:10
@ InvalidKey
The private key could not be loaded.
@ NotFound
HTTP 404.
@ NetworkError
The request did not complete (DNS, TLS, timeout, reset), or HTTP 408.
@ RateLimited
HTTP 429, or a local rate limit that would wait too long.
@ ServerError
HTTP 5xx.
@ SigningError
The request could not be signed.
@ InvalidRequest
Rejected before sending, or another HTTP 4xx.
@ AuthenticationError
HTTP 401 or 403.
@ ParseError
The response was not the JSON the API documents.
Definition error.hpp:23
static Error network(std::string msg)
Definition error.hpp:31
static Error auth(std::string msg)
Definition error.hpp:35
std::string api_code
Kalshi's machine-readable error code, such as "market_not_found", when sent.
Definition error.hpp:29
int http_status
HTTP status when the server answered; 0 otherwise.
Definition error.hpp:27
static Error parse(std::string msg)
Definition error.hpp:39
std::string message
Definition error.hpp:25
static Error signing(std::string msg)
Definition error.hpp:43
ErrorCode code
Definition error.hpp:24