Skip to content

Commit

Permalink
Expose more error information from http admin API
Browse files Browse the repository at this point in the history
  • Loading branch information
orbitalturtle committed Jun 7, 2022
1 parent 97a6f7a commit f1960bc
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 54 deletions.
18 changes: 16 additions & 2 deletions senseicore/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ use std::{
io::ErrorKind,
};

use crate::services;

#[derive(Debug)]
pub enum Error {
Db(migration::DbErr),
Expand All @@ -28,11 +30,14 @@ pub enum Error {
LdkInvoiceParse(lightning_invoice::ParseOrSemanticError),
InvalidSeedLength,
FailedToWriteSeed,
Unauthenticated,
Unauthenticated(String),
InvalidMacaroon,
AdminNodeNotFound,
AdminNodeNotStarted,
AdminNodeNotCreated,
FundingGenerationNeverHappened,
AdminNodeService,
UnknownResponse,
}

impl Display for Error {
Expand All @@ -52,13 +57,16 @@ impl Display for Error {
Error::LdkInvoiceParse(e) => e.to_string(),
Error::InvalidSeedLength => String::from("invalid seed length"),
Error::FailedToWriteSeed => String::from("failed to write seed"),
Error::Unauthenticated => String::from("unauthenticated"),
Error::Unauthenticated(msg) => String::from(format!("unauthenticated: {}", msg)),
Error::InvalidMacaroon => String::from("invalid macaroon"),
Error::AdminNodeNotFound => String::from("admin node not found"),
Error::AdminNodeNotCreated => String::from("admin node not created"),
Error::AdminNodeNotStarted => String::from("admin node not started"),
Error::FundingGenerationNeverHappened => {
String::from("funding generation for request never happened")
}
Error::AdminNodeService => String::from("admin node service error"),
Error::UnknownResponse => String::from("unknown response"),
};
write!(f, "{}", str)
}
Expand Down Expand Up @@ -136,6 +144,12 @@ impl From<macaroon::MacaroonError> for Error {
}
}

impl From<services::admin::Error> for Error {
fn from(_: services::admin::Error) -> Self {
Error::AdminNodeService
}
}

impl From<Error> for std::io::Error {
fn from(e: Error) -> std::io::Error {
std::io::Error::new(ErrorKind::Other, e.to_string())
Expand Down
Loading

0 comments on commit f1960bc

Please sign in to comment.