api: Update error messages

This commit is contained in:
Jonas Platte 2022-04-26 16:25:55 +02:00 committed by Jonas Platte
parent 0cdd6a7b0f
commit 22fbb8e0dc

View File

@ -61,22 +61,22 @@ impl EndpointError for MatrixError {
#[non_exhaustive] #[non_exhaustive]
pub enum IntoHttpError { pub enum IntoHttpError {
/// Tried to create an authentication request without an access token. /// Tried to create an authentication request without an access token.
#[error( #[error("no access token given, but this endpoint requires one")]
"This endpoint has to be converted to http::Request using \
try_into_authenticated_http_request"
)]
NeedsAuthentication, NeedsAuthentication,
/// Tried to create a request with an old enough version, for which no unstable endpoint /// Tried to create a request with an old enough version, for which no unstable endpoint
/// exists. /// exists.
/// ///
/// This is also a fallback error for if the version is too new for this endpoint. /// This is also a fallback error for if the version is too new for this endpoint.
#[error("Endpoint was not supported by server-reported versions, but no unstable path to fall back to was defined.")] #[error(
"endpoint was not supported by server-reported versions, \
but no unstable path to fall back to was defined"
)]
NoUnstablePath, NoUnstablePath,
/// Tried to create a request with [`MatrixVersion`]s for all of which this endpoint was /// Tried to create a request with [`MatrixVersion`]s for all of which this endpoint was
/// removed. /// removed.
#[error("Could not create any path variant for endpoint, as it was removed in version {0}")] #[error("could not create any path variant for endpoint, as it was removed in version {0}")]
EndpointRemoved(MatrixVersion), EndpointRemoved(MatrixVersion),
/// JSON serialization failed. /// JSON serialization failed.
@ -84,11 +84,11 @@ pub enum IntoHttpError {
Json(#[from] serde_json::Error), Json(#[from] serde_json::Error),
/// Query parameter serialization failed. /// Query parameter serialization failed.
#[error("Query parameter serialization failed: {0}")] #[error("query parameter serialization failed: {0}")]
Query(#[from] crate::serde::urlencoded::ser::Error), Query(#[from] crate::serde::urlencoded::ser::Error),
/// Header serialization failed. /// Header serialization failed.
#[error("Header serialization failed: {0}")] #[error("header serialization failed: {0}")]
Header(#[from] http::header::InvalidHeaderValue), Header(#[from] http::header::InvalidHeaderValue),
/// HTTP request construction failed. /// HTTP request construction failed.
@ -235,23 +235,23 @@ impl<E: StdError> StdError for ServerError<E> {}
#[non_exhaustive] #[non_exhaustive]
pub enum DeserializationError { pub enum DeserializationError {
/// Encountered invalid UTF-8. /// Encountered invalid UTF-8.
#[error("{0}")] #[error(transparent)]
Utf8(#[from] std::str::Utf8Error), Utf8(#[from] std::str::Utf8Error),
/// JSON deserialization failed. /// JSON deserialization failed.
#[error("{0}")] #[error(transparent)]
Json(#[from] serde_json::Error), Json(#[from] serde_json::Error),
/// Query parameter deserialization failed. /// Query parameter deserialization failed.
#[error("{0}")] #[error(transparent)]
Query(#[from] crate::serde::urlencoded::de::Error), Query(#[from] crate::serde::urlencoded::de::Error),
/// Got an invalid identifier. /// Got an invalid identifier.
#[error("{0}")] #[error(transparent)]
Ident(#[from] crate::IdParseError), Ident(#[from] crate::IdParseError),
/// Header value deserialization failed. /// Header value deserialization failed.
#[error("{0}")] #[error(transparent)]
Header(#[from] HeaderDeserializationError), Header(#[from] HeaderDeserializationError),
} }
@ -276,7 +276,7 @@ pub enum HeaderDeserializationError {
ToStrError(http::header::ToStrError), ToStrError(http::header::ToStrError),
/// The given required header is missing. /// The given required header is missing.
#[error("Missing header `{0}`")] #[error("missing header `{0}`")]
MissingHeader(String), MissingHeader(String),
} }
@ -287,7 +287,7 @@ pub struct UnknownVersionError;
impl fmt::Display for UnknownVersionError { impl fmt::Display for UnknownVersionError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Version string was unknown.") write!(f, "version string was unknown")
} }
} }