Struct NeonSqlError
#[non_exhaustive]pub struct NeonSqlError {
pub message: String,
pub code: Option<String>,
pub detail: Option<String>,
pub hint: Option<String>,
pub severity: Option<String>,
}Expand description
The error body Neon’s /sql endpoint returns when Postgres rejects a
statement.
The endpoint answers with a 4xx status and this JSON, so a SQL error is an
answer, not a transport failure. Preserving it structurally — rather than
stringifying it — is what lets a caller act on SQLSTATE 40001 (serialisation
failure, retry) differently from 23505 (unique violation, do not).
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.message: StringThe primary human-readable message.
code: Option<String>The five-character SQLSTATE, when the endpoint supplied one.
detail: Option<String>Postgres’ DETAIL.
hint: Option<String>Postgres’ HINT.
severity: Option<String>ERROR, FATAL or PANIC.
Implementations§
§impl NeonSqlError
impl NeonSqlError
pub fn is_serialization_failure(&self) -> bool
pub fn is_serialization_failure(&self) -> bool
SQLSTATE 40001: the transaction was aborted to preserve
serialisability.
Only reachable at IsolationLevel::Serializable,
and the reason that level is worth its cost here: it is the one
mechanism that makes a single-statement conditional insert safe without
a schema-level exclusion constraint.
pub fn is_unique_violation(&self) -> bool
pub fn is_unique_violation(&self) -> bool
SQLSTATE 23505: a unique constraint was violated.
Trait Implementations§
§impl Clone for NeonSqlError
impl Clone for NeonSqlError
§impl Debug for NeonSqlError
impl Debug for NeonSqlError
§impl<'de> Deserialize<'de> for NeonSqlError
impl<'de> Deserialize<'de> for NeonSqlError
§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>,
§impl Display for NeonSqlError
impl Display for NeonSqlError
§impl Error for NeonSqlError
impl Error for NeonSqlError
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()