* feat: Better "Archive" header error, don't report some HAWK errors

Closes: #771, #772
This commit is contained in:
JR Conlin 2020-08-19 09:24:19 -07:00 committed by GitHub
parent af5234d4ce
commit c11b3af354
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 2 deletions

View File

@ -24,7 +24,7 @@ use serde::{
use crate::db::error::{DbError, DbErrorKind};
use crate::server::metrics::Metrics;
use crate::server::ServerState;
use crate::web::error::{HawkError, ValidationError, ValidationErrorKind};
use crate::web::error::{HawkError, HawkErrorKind, ValidationError, ValidationErrorKind};
use crate::web::extractors::RequestErrorLocation;
/// Legacy Sync 1.1 error codes, which Sync 1.5 also returns by replacing the descriptive JSON
@ -127,6 +127,11 @@ impl ApiError {
DbErrorKind::Conflict => return false,
_ => (),
},
ApiErrorKind::Hawk(hawke) => match hawke.kind() {
HawkErrorKind::MissingHeader => return false,
HawkErrorKind::InvalidHeader => return false,
_ => (),
},
_ => (),
}
true

View File

@ -24,6 +24,12 @@ pub struct HawkError {
inner: Context<HawkErrorKind>,
}
impl HawkError {
pub fn kind(&self) -> &HawkErrorKind {
self.inner.get_context()
}
}
/// Causes of HAWK errors.
#[derive(Debug, Fail)]
pub enum HawkErrorKind {

View File

@ -788,7 +788,7 @@ impl FromRequest for CollectionRequest {
"application/json" | "" => ReplyFormat::Json,
_ => {
return Err(ValidationErrorKind::FromDetails(
"Invalid accept".to_string(),
format!("Invalid Accept header specified: {:?}", accept),
RequestErrorLocation::Header,
Some("accept".to_string()),
Some(tags),