mirror of
https://github.com/scottlamb/moonfire-nvr.git
synced 2025-12-05 07:12:34 -05:00
log error messages in web paths
HTTP requests were only returning the error message to the caller, not logging locally. In most cases the problem could be understood client-side, but there are some exceptions. E.g. if Moonfire returns a 403 on WebSocket update, even in the Chrome debug tools's network tab the HTTP response body seems to be unavailable. And in general, it's nice to have more context server-side. Logging a `response::Body` isn't practical (it could be a stream), so convert all the web stuff to use `base::Error` err returns. Convert the `METHOD_NOT_ALLOWED` paths to return `Ok` for now. This is a bit lame but punts on having some way of plumbing an explicit/overridden status code in `base::Error`, as no gRPC error kind cleanly maps to that. Also convert `db::auth`, rather than making up an error kind in the web layer. This is also a small step toward getting rid of `failure::Error`.
This commit is contained in:
@@ -36,6 +36,7 @@ use crate::schema;
|
||||
use crate::signal;
|
||||
use base::bail_t;
|
||||
use base::clock::{self, Clocks};
|
||||
use base::format_err_t;
|
||||
use base::strutil::encode_size;
|
||||
use failure::{bail, format_err, Error, ResultExt};
|
||||
use fnv::{FnvHashMap, FnvHashSet};
|
||||
@@ -338,11 +339,13 @@ impl SampleFileDir {
|
||||
/// Returns a cloned copy of the directory, or Err if closed.
|
||||
///
|
||||
/// Use `LockedDatabase::open_sample_file_dirs` prior to calling this method.
|
||||
pub fn get(&self) -> Result<Arc<dir::SampleFileDir>, Error> {
|
||||
pub fn get(&self) -> Result<Arc<dir::SampleFileDir>, base::Error> {
|
||||
Ok(self
|
||||
.dir
|
||||
.as_ref()
|
||||
.ok_or_else(|| format_err!("sample file dir {} is closed", self.id))?
|
||||
.ok_or_else(|| {
|
||||
format_err_t!(FailedPrecondition, "sample file dir {} is closed", self.id)
|
||||
})?
|
||||
.clone())
|
||||
}
|
||||
|
||||
@@ -2087,7 +2090,7 @@ impl LockedDatabase {
|
||||
password: String,
|
||||
domain: Option<Vec<u8>>,
|
||||
session_flags: i32,
|
||||
) -> Result<(RawSessionId, &Session), Error> {
|
||||
) -> Result<(RawSessionId, &Session), base::Error> {
|
||||
self.auth
|
||||
.login_by_password(&self.conn, req, username, password, domain, session_flags)
|
||||
}
|
||||
@@ -2099,7 +2102,7 @@ impl LockedDatabase {
|
||||
domain: Option<Vec<u8>>,
|
||||
flags: i32,
|
||||
permissions: schema::Permissions,
|
||||
) -> Result<(RawSessionId, &Session), Error> {
|
||||
) -> Result<(RawSessionId, &Session), base::Error> {
|
||||
self.auth
|
||||
.make_session(&self.conn, creation, uid, domain, flags, permissions)
|
||||
}
|
||||
@@ -2118,7 +2121,7 @@ impl LockedDatabase {
|
||||
detail: Option<String>,
|
||||
req: auth::Request,
|
||||
hash: &auth::SessionHash,
|
||||
) -> Result<(), Error> {
|
||||
) -> Result<(), base::Error> {
|
||||
self.auth
|
||||
.revoke_session(&self.conn, reason, detail, req, hash)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user