client-api: Make Error non-exhaustive
This commit is contained in:
parent
c5f8137ba9
commit
4f4085a013
@ -13,6 +13,7 @@ Breaking changes:
|
|||||||
- The `ts` field in `Request` for `get_media_preview` is now `Option`.
|
- The `ts` field in `Request` for `get_media_preview` is now `Option`.
|
||||||
- The query parameter of `check_registration_token_validity` endpoint
|
- The query parameter of `check_registration_token_validity` endpoint
|
||||||
has been renamed from `registration_token` to `token`
|
has been renamed from `registration_token` to `token`
|
||||||
|
- `Error` is now non-exhaustive.
|
||||||
|
|
||||||
Improvements:
|
Improvements:
|
||||||
|
|
||||||
|
@ -298,7 +298,7 @@ pub struct StandardErrorBody {
|
|||||||
|
|
||||||
/// A Matrix Error
|
/// A Matrix Error
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
#[allow(clippy::exhaustive_structs)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
pub struct Error {
|
pub struct Error {
|
||||||
/// The http status code.
|
/// The http status code.
|
||||||
pub status_code: http::StatusCode,
|
pub status_code: http::StatusCode,
|
||||||
@ -312,6 +312,18 @@ pub struct Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Error {
|
impl Error {
|
||||||
|
/// Constructs a new `Error` with the given status code and body.
|
||||||
|
///
|
||||||
|
/// This is equivalent to calling `body.into_error(status_code)`.
|
||||||
|
pub fn new(status_code: http::StatusCode, body: ErrorBody) -> Self {
|
||||||
|
Self {
|
||||||
|
status_code,
|
||||||
|
#[cfg(feature = "unstable-msc2967")]
|
||||||
|
authenticate: None,
|
||||||
|
body,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// If `self` is a server error in the `errcode` + `error` format expected
|
/// If `self` is a server error in the `errcode` + `error` format expected
|
||||||
/// for client-server API endpoints, returns the error kind (`errcode`).
|
/// for client-server API endpoints, returns the error kind (`errcode`).
|
||||||
pub fn error_kind(&self) -> Option<&ErrorKind> {
|
pub fn error_kind(&self) -> Option<&ErrorKind> {
|
||||||
@ -368,6 +380,8 @@ impl std::error::Error for Error {}
|
|||||||
|
|
||||||
impl ErrorBody {
|
impl ErrorBody {
|
||||||
/// Convert the ErrorBody into an Error by adding the http status code.
|
/// Convert the ErrorBody into an Error by adding the http status code.
|
||||||
|
///
|
||||||
|
/// This is equivalent to calling `Error::new(status_code, self)`.
|
||||||
pub fn into_error(self, status_code: http::StatusCode) -> Error {
|
pub fn into_error(self, status_code: http::StatusCode) -> Error {
|
||||||
Error {
|
Error {
|
||||||
status_code,
|
status_code,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user