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 10, 2022
1 parent e772430 commit 066d074
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 60 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 @@ -30,12 +32,15 @@ pub enum Error {
FailedToWriteSeed,
SeedNotFound,
MacaroonNotFound,
Unauthenticated,
Unauthenticated(String),
InvalidMacaroon,
AdminNodeNotFound,
AdminNodeNotStarted,
AdminNodeNotCreated,
FundingGenerationNeverHappened,
NodeBeingStartedAlready,
AdminNodeService(services::admin::Error),
UnknownResponse,
}

impl Display for Error {
Expand All @@ -57,14 +62,17 @@ impl Display for Error {
Error::SeedNotFound => String::from("seed not found for node"),
Error::MacaroonNotFound => String::from("macaroon not found for node"),
Error::FailedToWriteSeed => String::from("failed to write seed"),
Error::Unauthenticated => String::from("unauthenticated"),
Error::Unauthenticated(msg) => 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::NodeBeingStartedAlready => String::from("node already being started"),
Error::FundingGenerationNeverHappened => {
String::from("funding generation for request never happened")
}
Error::AdminNodeService(e) => format!("admin node service error: {}", e),
Error::UnknownResponse => String::from("unknown response"),
};
write!(f, "{}", str)
}
Expand Down Expand Up @@ -142,6 +150,12 @@ impl From<macaroon::MacaroonError> for Error {
}
}

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

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
11 changes: 11 additions & 0 deletions senseicore/src/services/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use lightning_background_processor::BackgroundProcessor;
use macaroon::Macaroon;
use serde::{Deserialize, Serialize};
use std::collections::{HashMap, HashSet, VecDeque};
use std::fmt::{self, Display};
use std::sync::atomic::Ordering;
use std::{collections::hash_map::Entry, fs, sync::Arc};
use tokio::sync::{broadcast, Mutex};
Expand Down Expand Up @@ -216,6 +217,16 @@ pub enum Error {
Generic(String),
}

impl Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// nEED TO DO THIS MATCH HERE???
let str = match self {
Error::Generic(e) => e.to_string(),
};
write!(f, "{}", str)
}
}

impl From<std::io::Error> for Error {
fn from(e: std::io::Error) -> Self {
Self::Generic(e.to_string())
Expand Down
Loading

0 comments on commit 066d074

Please sign in to comment.