Skip to content

Commit abd790b

Browse files
committed
feat(error): implement Display for Error
Instead of deferring to the `Debug` implementations.
1 parent f50c495 commit abd790b

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

src/lib.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,35 @@ pub enum Error {
311311

312312
impl fmt::Display for Error {
313313
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
314-
write!(f, "{self:?}")
314+
match self {
315+
#[cfg(any(feature = "blocking", feature = "async"))]
316+
Error::BitReq(e) => write!(f, "Bitreq HTTP error: {e}"),
317+
Error::SerdeJson(e) => write!(f, "JSON (de)serialization error: {e}"),
318+
Error::HttpResponse { status, message } => {
319+
write!(f, "HTTP error {status}: {message}")
320+
}
321+
Error::Parsing(e) => write!(f, "Failed to parse invalid number: {e}"),
322+
Error::StatusCode(e) => write!(f, "Invalid status code: {e}"),
323+
Error::BitcoinEncoding(e) => write!(f, "Invalid Bitcoin data: {e}"),
324+
Error::HexToArray(e) => write!(f, "Invalid hex to array conversion: {e}"),
325+
Error::HexToBytes(e) => write!(f, "Invalid hex to bytes conversion: {e}"),
326+
Error::TransactionNotFound(txid) => {
327+
write!(f, "Transaction not found: {txid}")
328+
}
329+
Error::HeaderHeightNotFound(height) => {
330+
write!(f, "Block header at height {height} not found")
331+
}
332+
Error::HeaderHashNotFound(hash) => {
333+
write!(f, "Block header with hash {hash} not found")
334+
}
335+
Error::InvalidHttpHeaderName(name) => {
336+
write!(f, "Invalid HTTP header name: {name}")
337+
}
338+
Error::InvalidHttpHeaderValue(value) => {
339+
write!(f, "Invalid HTTP header value: {value}")
340+
}
341+
Error::InvalidResponse => write!(f, "The server sent an invalid response"),
342+
}
315343
}
316344
}
317345

0 commit comments

Comments
 (0)