Start improving client facing errors

This commit is contained in:
Dominik Werder
2024-08-20 16:16:43 +02:00
parent cb92317bf6
commit 7a8d071c7a
23 changed files with 984 additions and 654 deletions

View File

@@ -63,7 +63,9 @@ use bytes::Bytes;
use chrono::DateTime;
use chrono::TimeZone;
use chrono::Utc;
use err::thiserror;
use err::Error;
use err::ThisError;
use futures_util::Stream;
use futures_util::StreamExt;
use http::Request;
@@ -103,6 +105,7 @@ pub const APP_CBOR_FRAMED: &str = "application/cbor-framed";
pub const APP_JSON_FRAMED: &str = "application/json-framed";
pub const ACCEPT_ALL: &str = "*/*";
pub const X_DAQBUF_REQID: &str = "x-daqbuffer-request-id";
pub const HEADER_NAME_REQUEST_ID: &str = "requestid";
pub const CONNECTION_STATUS_DIV: DtMs = DtMs::from_ms_u64(1000 * 60 * 60);
// pub const TS_MSP_GRID_UNIT: DtMs = DtMs::from_ms_u64(1000 * 10);
@@ -176,6 +179,13 @@ impl CmpZero for usize {
}
}
#[derive(Debug, err::ThisError)]
#[cstm(name = "AsyncChannelError")]
pub enum AsyncChannelError {
Send,
Recv,
}
pub struct BodyStream {
//pub receiver: async_channel::Receiver<Result<Bytes, Error>>,
pub inner: Box<dyn Stream<Item = Result<Bytes, Error>> + Send + Unpin>,
@@ -1071,6 +1081,16 @@ impl SfDbChannel {
}
}
impl fmt::Display for SfDbChannel {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(
fmt,
"SfDbChannel {{ series: {:?}, backend: {:?}, name: {:?}, kind: {:?} }}",
self.series, self.backend, self.name, self.kind
)
}
}
impl FromUrl for SfDbChannel {
fn from_url(url: &Url) -> Result<Self, Error> {
let pairs = get_url_query_pairs(url);
@@ -4123,14 +4143,18 @@ pub fn status_board_init() {
});
}
pub fn req_uri_to_url(uri: &Uri) -> Result<Url, Error> {
#[derive(Debug, ThisError)]
#[cstm(name = "UriError")]
pub enum UriError {
ParseError(Uri),
}
pub fn req_uri_to_url(uri: &Uri) -> Result<Url, UriError> {
if uri.scheme().is_none() {
format!("dummy:{uri}")
.parse()
.map_err(|_| Error::with_msg_no_trace(format!("can not use uri {uri}")))
.map_err(|_| UriError::ParseError(uri.clone()))
} else {
uri.to_string()
.parse()
.map_err(|_| Error::with_msg_no_trace(format!("can not use uri {uri}")))
uri.to_string().parse().map_err(|_| UriError::ParseError(uri.clone()))
}
}

View File

@@ -60,6 +60,12 @@ impl fmt::Debug for NanoRange {
}
}
impl fmt::Display for NanoRange {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt::Debug::fmt(self, fmt)
}
}
impl NanoRange {
pub fn from_date_time(beg: DateTime<Utc>, end: DateTime<Utc>) -> Self {
Self {