pub struct DatabaseError {
pub code: String,
pub message: String,
pub details: Option<String>,
pub hint: Option<String>,
pub constraint: Option<String>,
pub table: Option<String>,
pub column: Option<String>,
}Expand description
Database-specific error type.
Fields§
§code: StringThe five-character SQLSTATE. This decides the HTTP status, so it is the field that matters most.
message: StringPostgreSQL’s primary message.
details: Option<String>PostgreSQL’s detail field, where it sent one.
hint: Option<String>PostgreSQL’s hint field, where it sent one.
constraint: Option<String>The constraint that was violated, for the integrity SQLSTATEs.
table: Option<String>The table the failure concerns, where PostgreSQL identified one.
column: Option<String>The column the failure concerns, where PostgreSQL identified one.
Implementations§
Source§impl DatabaseError
impl DatabaseError
Sourcepub fn raised_response(&self) -> Option<Result<RaisedResponse, RaiseFault>>
pub fn raised_response(&self) -> Option<Result<RaisedResponse, RaiseFault>>
The response a RAISE sqlstate 'PGRST' asked for.
A function can take over the whole response by raising that SQLSTATE: the message is the body, and the detail carries the status, an optional status text and any headers. It is how a schema returns a 402 with its own payload without the API layer knowing anything about billing.
PostgREST rebuilds the body as {code, message, details, hint}, which
is no use to a schema that replaces an API whose errors have another
shape. So a body key in the detail, of any JSON type, is the body
instead, byte for byte; the message is then only what gets logged, and
may be free text, and headers is optional. PostgREST has no such key
and ignores it, so no schema written for it is affected.
None when this is not that error. Err when it is and the schema
wrote it wrongly, which is a bug in the schema rather than a response
to half-apply.
Sourcepub fn status_is_raised(&self) -> bool
pub fn status_is_raised(&self) -> bool
Whether the schema chose the status itself, by raising sqlstate 'PGRST' or a PT<nnn> code, rather than leaving it to the table.
Such a status is a request and not a classification, so configuration that maps SQLSTATEs to statuses does not apply to it.
Sourcepub fn status_code(&self) -> StatusCode
pub fn status_code(&self) -> StatusCode
The HTTP status a PostgreSQL error code maps to.
PostgREST’s table (mapSQLtoHTTP in Error.hs), which is part of its
contract rather than an implementation detail: a client distinguishes a
missing function from a bad argument by the status.
The default is 400, not 500: the great majority of SQLSTATEs a request can provoke are provoked by the request. Reporting them as server errors tells the client to retry something that will never succeed.
Sourcepub fn status_code_as(&self, authenticated: bool) -> StatusCode
pub fn status_code_as(&self, authenticated: bool) -> StatusCode
The HTTP status for a request that is or is not authenticated.
The same table as status_code, which has the
answer for an anonymous request. Only 42501 (insufficient privilege)
depends on who asked, as it does in PostgREST: 401 for an anonymous
request, which may simply not have said who it is, and 403 for an
authenticated one, which has and is still not permitted. “Authenticated”
means the request runs as a role other than the configured anonymous
role, see
AppConfig::is_authenticated_role.
Sourcepub fn is_unwritable_view(&self) -> bool
pub fn is_unwritable_view(&self) -> bool
Whether this is PostgreSQL refusing a write to a view it cannot write
through: one that is not automatically updatable and has no INSTEAD OF trigger or rule for the operation, or a materialized view.
That is a method the resource does not take, whoever asks – a 405,
not the 500 its SQLSTATE (55000, object not in prerequisite state)
would otherwise be. Read from the message, as xmlagg and the missing
role are, because the SQLSTATE alone covers unrelated faults too; a
server whose lc_messages is not English keeps the 500.
Trait Implementations§
Source§impl Debug for DatabaseError
impl Debug for DatabaseError
Source§impl Display for DatabaseError
impl Display for DatabaseError
Source§impl Error for DatabaseError
impl Error for DatabaseError
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()
Source§impl From<DatabaseError> for Error
impl From<DatabaseError> for Error
Source§fn from(source: DatabaseError) -> Self
fn from(source: DatabaseError) -> Self
Auto Trait Implementations§
impl Forget for DatabaseError
impl Freeze for DatabaseError
impl Move for DatabaseError
impl RefUnwindSafe for DatabaseError
impl Send for DatabaseError
impl Sync for DatabaseError
impl Unpin for DatabaseError
impl UnsafeUnpin for DatabaseError
impl UnwindSafe for DatabaseError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more