#[non_exhaustive]pub enum OcpiError {
Show 13 variants
Remote {
status_code: StatusCode,
status_message: Option<String>,
},
MissingData {
status_code: StatusCode,
},
MalformedJson(String),
Decode {
path: String,
message: String,
},
Invalid(Violations),
Unauthorized(String),
TokenAOutOfScope,
NotFound(String),
MethodNotAllowed(String),
Transport(String),
NotRoutable(String),
Unsupported(String),
UrlRefused {
url: String,
reason: String,
},
}transport only.Expand description
Everything that can go wrong on an OCPI request, from either side of the wire.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Remote
The peer answered with a non-success OCPI status code.
Fields
status_code: StatusCodeThe code the peer sent.
MissingData
A successful response did not carry the payload the endpoint documents.
Fields
status_code: StatusCodeThe code the peer sent.
MalformedJson(String)
The request body was not valid JSON, so it never reached the OCPI layer.
When a message does not contain a valid JSON string, the HTTP error
400 - Bad requestMUST be returned.
Decode
The body was valid JSON but did not fit the OCPI object it was supposed to be.
path is the JSON path to the offending value, which is what turns a support ticket into
a one-line fix.
Fields
Invalid(Violations)
A decoded object broke rules of the specification.
No credentials token, or one that matches no known party.
If the header is missing or the credentials token doesn’t match any known party then the server SHALL respond with an HTTP
401 - Unauthorizedstatus code.
TokenAOutOfScope
CREDENTIALS_TOKEN_A was used on a module other than credentials or versions.
the server SHALL respond with an HTTP
401 - Unauthorizedstatus code.
NotFound(String)
A GET addressed a resource that does not exist.
In case of a GET request, when the resource does NOT exist, the server SHOULD return a HTTP
404 - Not Found.
MethodNotAllowed(String)
The HTTP method is not allowed in the current registration state.
The credentials module uses this: POST when already registered, PUT or DELETE when not.
Transport(String)
The transport failed: connection refused, TLS failure, timeout, non-JSON body.
NotRoutable(String)
A hub was asked to route a request whose headers and method do not describe any of the scenarios the specification defines.
The clearest example is a GET addressed to the hub’s own party on a Receiver interface:
the OCPI-to- headers say Broadcast Push, but “GET SHALL NOT be used in combination
with Broadcast Push”, and the sender is told to use an Open Routing Request instead.
Spec: 2.3.0 §transport_and_format_message_routing
Unsupported(String)
This build cannot carry a document between the two OCPI versions involved.
A client whose peer speaks a version this crate has no conversions for, or a merge patch
that writes a field the two versions disagree about. It is a 3000 rather than a 2001
because nothing about the request is wrong: the software simply cannot do it.
UrlRefused
A URL was refused by the configured UrlPolicy.
Implementations§
Source§impl OcpiError
impl OcpiError
Sourcepub fn status_code(&self) -> StatusCode
pub fn status_code(&self) -> StatusCode
The OCPI status code this error should be reported as.
Sourcepub const fn http_status(&self) -> u16
pub const fn http_status(&self) -> u16
The HTTP status code this error should be answered with.
This encodes the whole of §status_codes: the only cases that get an HTTP error are the
ones the spec explicitly names. Everything that reached the OCPI layer is HTTP 200 with
a 2xxx/3xxx/4xxx status_code in the body.
| Situation | HTTP |
|---|---|
| body is not valid JSON | 400 |
| missing or unknown credentials token | 401 |
CREDENTIALS_TOKEN_A outside credentials/versions | 401 |
| GET of a resource that does not exist | 404 |
| credentials POST when registered, PUT/DELETE when not | 405 |
| anything else | 200 |
Spec: 2.3.0 §status_codes_status_codes
Sourcepub fn is_transient(&self) -> bool
pub fn is_transient(&self) -> bool
Whether retrying the same request could plausibly succeed.
The spec forbids automatically retrying a write:
OCPI messages SHOULD NOT be queued. When a client does a POST, PUT or PATCH request and that request fails or times out, the client should not queue the message and retry the same message again later.
So this is only ever consulted for GETs; see
RetryPolicy.
Sourcepub fn to_response<T>(&self) -> OcpiResponse<T>
pub fn to_response<T>(&self) -> OcpiResponse<T>
Renders this error as the envelope a server should send back.
Trait Implementations§
Source§impl Error for OcpiError
impl Error for OcpiError
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<OcpiError> for OcpiErrorResponse
Available on crate feature server only.
impl From<OcpiError> for OcpiErrorResponse
server only.Source§impl From<Violations> for OcpiError
impl From<Violations> for OcpiError
Source§fn from(source: Violations) -> Self
fn from(source: Violations) -> Self
Source§impl IntoResponse for OcpiError
Available on crate feature server only.
impl IntoResponse for OcpiError
server only.