Skip to main content

OcpiError

Enum OcpiError 

Source
#[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, },
}
Available on crate feature 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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Remote

The peer answered with a non-success OCPI status code.

Fields

§status_code: StatusCode

The code the peer sent.

§status_message: Option<String>

The message the peer sent, if any.

§

MissingData

A successful response did not carry the payload the endpoint documents.

Fields

§status_code: StatusCode

The 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 request MUST 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

§path: String

JSON path to the value that did not decode.

§message: String

What went wrong there.

§

Invalid(Violations)

A decoded object broke rules of the specification.

§

Unauthorized(String)

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 - Unauthorized status code.

§

TokenAOutOfScope

CREDENTIALS_TOKEN_A was used on a module other than credentials or versions.

the server SHALL respond with an HTTP 401 - Unauthorized status 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.

Fields

§url: String

The URL that was refused.

§reason: String

Why it was refused.

Implementations§

Source§

impl OcpiError

Source

pub fn status_code(&self) -> StatusCode

The OCPI status code this error should be reported as.

Source

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.

SituationHTTP
body is not valid JSON400
missing or unknown credentials token401
CREDENTIALS_TOKEN_A outside credentials/versions401
GET of a resource that does not exist404
credentials POST when registered, PUT/DELETE when not405
anything else200

Spec: 2.3.0 §status_codes_status_codes

Source

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.

Source

pub fn to_response<T>(&self) -> OcpiResponse<T>

Renders this error as the envelope a server should send back.

Trait Implementations§

Source§

impl Debug for OcpiError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for OcpiError

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for OcpiError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<OcpiError> for OcpiErrorResponse

Available on crate feature server only.
Source§

fn from(error: OcpiError) -> Self

Converts to this type from the input type.
Source§

impl From<Violations> for OcpiError

Source§

fn from(source: Violations) -> Self

Converts to this type from the input type.
Source§

impl IntoResponse for OcpiError

Available on crate feature server only.
Source§

fn into_response(self) -> Response

Create a response.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more