Ensure error is returned when NS/DB header are not present

This commit is contained in:
Tobie Morgan Hitchcock 2022-07-29 10:35:15 +01:00
parent 2646ea119e
commit f46acec96f
2 changed files with 14 additions and 2 deletions

View file

@ -14,6 +14,12 @@ pub enum Error {
#[error("The request body contains invalid data")]
Request,
#[error("There was no NS header present in the request")]
NoNsHeader,
#[error("There was no DB header present in the request")]
NoDbHeader,
#[error("There was a problem with authentication")]
InvalidAuth,

View file

@ -21,9 +21,15 @@ async fn handler(session: Session) -> Result<impl warp::Reply, warp::Rejection>
// Get the datastore reference
let db = DB.get().unwrap();
// Extract the NS header value
let nsv = session.ns.clone().unwrap();
let nsv = match session.ns {
Some(ns) => ns,
None => return Err(warp::reject::custom(Error::NoNsHeader)),
};
// Extract the DB header value
let dbv = session.db.clone().unwrap();
let dbv = match session.db {
Some(db) => db,
None => return Err(warp::reject::custom(Error::NoDbHeader)),
};
// Create a chunked response
let (mut chn, bdy) = Body::channel();
// Create a new bounded channel