pub enum WebhookError {
MissingHeader(String),
MalformedPayload(String),
InvalidSignature(String),
ReplayDetected(String),
Backend(String),
}Expand description
Why a webhook verification failed, classified so callers can map the variant onto an HTTP response code.
The inner String carries vendor-provided detail ("timestamp 123 is 412s old, max 300s", "signature byte mismatch at index 7", …) suitable for logs and error pages. Do not parse it; use
the variant for branching.
HTTP mapping (enforced at the middleware layer, not here):
| Variant | HTTP status | Safe to retry? |
|---|---|---|
MissingHeader | 400 | No — fix the sender. |
MalformedPayload | 400 | No — fix the sender. |
InvalidSignature | 401 | No — wrong secret. |
ReplayDetected | 401 | No — resend with new ts. |
Backend | 500 | Yes, once. |
Variants§
MissingHeader(String)
A header the scheme requires is missing from the request. The inner string is the header name the plugin expected.
MalformedPayload(String)
A required header or body section exists but is syntactically
malformed (e.g. Stripe’s t=...,v1=... comma-list fails to
parse, Twilio’s URL can’t be reconstructed from the scheme +
host + path triple).
InvalidSignature(String)
The HMAC comparison failed — either the body was mutated in flight, the signing secret on this side is wrong, or the request is an outright forgery. Indistinguishable from the plugin’s point of view.
ReplayDetected(String)
A valid-looking request is too old to accept (Stripe default:
5 minutes, Slack default: 5 minutes). Resending with a fresh
timestamp would succeed, so this is distinct from
InvalidSignature.
Backend(String)
The plugin itself could not complete verification because of a host-side fault (secret missing from config, clock skew probe failed, underlying crypto library returned an error the plugin couldn’t classify). Middleware MUST NOT leak this back to the sender as a signature failure.
Implementations§
Source§impl WebhookError
impl WebhookError
pub fn missing_header(name: impl Into<String>) -> Self
pub fn malformed(detail: impl Into<String>) -> Self
pub fn invalid_signature(detail: impl Into<String>) -> Self
pub fn replay(detail: impl Into<String>) -> Self
pub fn backend(detail: impl Into<String>) -> Self
Sourcepub fn http_status(&self) -> u16
pub fn http_status(&self) -> u16
Recommended HTTP status code for this error. Middleware returning the response body MAY override — this is a hint, not a hard binding.
Trait Implementations§
Source§impl Clone for WebhookError
impl Clone for WebhookError
Source§fn clone(&self) -> WebhookError
fn clone(&self) -> WebhookError
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for WebhookError
impl Debug for WebhookError
Source§impl<'de> Deserialize<'de> for WebhookError
impl<'de> Deserialize<'de> for WebhookError
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for WebhookError
impl Display for WebhookError
Source§impl Error for WebhookError
impl Error for WebhookError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()