pub enum ApiError {
Unauthorized,
NotFound {
code: &'static str,
message: String,
},
BadRequest {
code: &'static str,
message: String,
},
Internal(String),
}Expand description
Every failure the API can report, with the JSON body clients receive.
§Deviation from the design
Phase 2 design §7 specified a nested body carrying the status twice
({"error": {"code", "message", "status"}}). The body here is flat —
{"error": "<code>", "message": "<text>"} — and the status is only in the
HTTP status line. Rationale: the status is already authoritative on the wire
and repeating it in the body is a second source of truth that can disagree
with the status line. Flattening also means an agent parses one object with
no branch before it can read the machine code.
error is a stable machine code drawn from a closed set
(ApiError::code) and is what a client should branch on. The codes are the
ones §7 enumerates; message is prose for humans and is not guaranteed to
be stable across releases.
§Why NotFound and BadRequest carry their own code
Both map to a single HTTP status, so the status alone cannot tell an agent
what went wrong: 404 covers both “no such index” and “no such node”, and
400 covers a missing param, an unparseable param, and a bad body. The
status says what kind of failure; the code says which, which is what
lets a client retry sensibly without matching on prose.
Variants§
No Authorization header, wrong scheme, unknown key, or wrong secret.
NotFound
The request was well-formed but names something that does not exist.
Fields
BadRequest
The request itself is malformed (missing field, bad value).
Fields
Internal(String)
Storage, indexing, or an unexpected internal failure.
Implementations§
Source§impl ApiError
impl ApiError
Sourcepub fn unknown_index(id: &str) -> Self
pub fn unknown_index(id: &str) -> Self
404 unknown_index: {id} does not name a database in the data dir.
Sourcepub fn unknown_node(id: &str) -> Self
pub fn unknown_node(id: &str) -> Self
404 unknown_node: the index loaded, but the node is not in the graph.
Sourcepub fn no_path(from: &str, to: &str) -> Self
pub fn no_path(from: &str, to: &str) -> Self
404 no_path: no typed path connects the two nodes.
Not in the §7 table, which does not cover a well-formed path query
whose answer is “these two symbols are unrelated”. The CLI rejects the
same case rather than returning an empty path, so 404 is preserved and
given its own code instead of being folded into unknown_index or
reported as an empty 200.
Sourcepub fn missing_param(name: &str) -> Self
pub fn missing_param(name: &str) -> Self
400 missing_param: a required query parameter is absent or empty.
Sourcepub fn invalid_param(name: &str, reason: &str) -> Self
pub fn invalid_param(name: &str, reason: &str) -> Self
400 invalid_param: a query parameter is present but unusable.
Sourcepub fn invalid_body(reason: &str) -> Self
pub fn invalid_body(reason: &str) -> Self
400 invalid_body: the request body is not the expected JSON shape.
Sourcepub fn invalid_repo_path(reason: &str) -> Self
pub fn invalid_repo_path(reason: &str) -> Self
400 invalid_repo_path: repo_path is missing or is not a directory.
Trait Implementations§
Source§impl Error for ApiError
impl Error for ApiError
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 IntoResponse for ApiError
impl IntoResponse for ApiError
Source§fn into_response(self) -> Response
fn into_response(self) -> Response
Auto Trait Implementations§
impl Freeze for ApiError
impl RefUnwindSafe for ApiError
impl Send for ApiError
impl Sync for ApiError
impl Unpin for ApiError
impl UnsafeUnpin for ApiError
impl UnwindSafe for ApiError
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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