ferriskey_sdk/error.rs
1//! Error types for the FerrisKey SDK transport layer.
2
3use serde_json::Value;
4use thiserror::Error;
5
6/// Errors raised by the transport implementation.
7#[derive(Debug, Error)]
8pub enum TransportError {
9 /// The request method could not be converted into an HTTP verb.
10 #[error("invalid HTTP method {method}")]
11 InvalidMethod {
12 /// Method string provided by the SDK request.
13 method: String,
14 },
15 /// The request could not be sent by the underlying HTTP client.
16 #[error("HTTP transport failure: {0}")]
17 Http(#[from] hpx::Error),
18}
19
20/// Errors raised by the SDK execution layer.
21#[derive(Debug, Error)]
22pub enum SdkError {
23 /// A documented API error payload was returned by the server.
24 #[error("operation {operation_id} returned API error status {status}")]
25 ApiResponse {
26 /// Decoded JSON body when the documented response payload is JSON.
27 body: Option<Value>,
28 /// Operation identifier used for the request.
29 operation_id: String,
30 /// Schema name documented for the matched response payload.
31 schema_name: Option<&'static str>,
32 /// HTTP status code returned by the server.
33 status: u16,
34 },
35 /// A secured request was attempted without configured credentials.
36 #[error("request requires bearer authentication but no bearer token is configured")]
37 MissingAuth,
38 /// A required path, query, or header parameter was not provided.
39 #[error("operation {operation_id} is missing required {location} parameter {name}")]
40 MissingParameter {
41 /// Parameter location in the HTTP request.
42 location: &'static str,
43 /// Parameter name.
44 name: String,
45 /// Operation identifier used for the request.
46 operation_id: String,
47 },
48 /// A required request body was omitted.
49 #[error("operation {operation_id} requires a request body")]
50 MissingRequestBody {
51 /// Operation identifier used for the request.
52 operation_id: String,
53 },
54 /// The response status did not match what the caller expected.
55 #[error("unexpected response status: expected {expected}, got {actual}")]
56 UnexpectedStatus {
57 /// Expected HTTP status code.
58 expected: u16,
59 /// Actual HTTP status code.
60 actual: u16,
61 },
62 /// The response body did not match the expected format.
63 #[error("failed to decode response body: {0}")]
64 Decode(#[from] serde_json::Error),
65 /// The configured base URL or request path could not be resolved.
66 #[error("failed to resolve request URL from base {base_url} and path {path}")]
67 InvalidUrl {
68 /// Base URL configured on the SDK.
69 base_url: String,
70 /// Path provided by the SDK request.
71 path: String,
72 },
73 /// The operation path template still contained unresolved placeholders after encoding.
74 #[error(
75 "operation {operation_id} has unresolved placeholders in path template {path_template}"
76 )]
77 InvalidPathTemplate {
78 /// Operation identifier used for the request.
79 operation_id: String,
80 /// Path template that could not be fully encoded.
81 path_template: String,
82 },
83 /// No generated descriptor matched the requested operation ID.
84 #[error("unknown FerrisKey operation: {operation_id}")]
85 UnknownOperation {
86 /// Operation identifier requested by the caller.
87 operation_id: String,
88 },
89 /// The underlying transport failed.
90 #[error(transparent)]
91 Transport(#[from] TransportError),
92}