qstash_rs/error.rs
1use reqwest::StatusCode;
2use thiserror::Error;
3
4/// Result alias used throughout the crate.
5pub type Result<T> = std::result::Result<T, Error>;
6
7/// Errors returned by the QStash client and receiver.
8#[derive(Debug, Error)]
9pub enum Error {
10 /// The client or request was configured with invalid input.
11 #[error("invalid configuration: {message}")]
12 Config {
13 /// Human-readable validation detail.
14 message: String,
15 },
16
17 /// The caller built an invalid request.
18 #[error("invalid request: {message}")]
19 InvalidRequest {
20 /// Human-readable validation detail.
21 message: String,
22 },
23
24 /// The underlying HTTP transport failed.
25 #[error("transport error: {0}")]
26 Transport(#[source] reqwest::Error),
27
28 /// JSON serialization failed before the request was sent.
29 #[error("failed to serialize request body: {0}")]
30 Serialize(#[source] serde_json::Error),
31
32 /// The QStash API returned a non-success status code.
33 #[error("qstash api error ({status}): {message}")]
34 Api {
35 /// HTTP status returned by QStash.
36 status: StatusCode,
37 /// Best-effort error message extracted from the response payload.
38 message: String,
39 /// Raw response body when one was returned.
40 body: Option<String>,
41 },
42
43 /// A success response could not be decoded into the expected model.
44 #[error("failed to decode response body with status {status}: {source}")]
45 Decode {
46 /// HTTP status returned by QStash.
47 status: StatusCode,
48 /// Raw response body.
49 body: String,
50 /// JSON decoding error.
51 #[source]
52 source: serde_json::Error,
53 },
54
55 /// JWT verification failed while validating an inbound QStash request.
56 #[error("jwt verification failed: {0}")]
57 Jwt(#[from] jsonwebtoken::errors::Error),
58
59 /// A verified JWT did not match the expected body or subject.
60 #[error("signature verification failed: {message}")]
61 Signature {
62 /// Human-readable verification detail.
63 message: String,
64 },
65}