web: fix return status for error page with localization
This commit is contained in:
parent
1022e1797b
commit
726d04aca7
|
@ -66,6 +66,16 @@ pub enum Query {
|
||||||
Invalid(),
|
Invalid(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Query {
|
||||||
|
pub fn is_invalid(&self) -> bool {
|
||||||
|
match self {
|
||||||
|
Query::Invalid() => true,
|
||||||
|
Query::InvalidShort() => true,
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl FromStr for Query {
|
impl FromStr for Query {
|
||||||
type Err = anyhow::Error;
|
type Err = anyhow::Error;
|
||||||
|
|
||||||
|
|
|
@ -281,6 +281,10 @@ pub fn key_to_response_plain(
|
||||||
i18n: I18n,
|
i18n: I18n,
|
||||||
query: Query,
|
query: Query,
|
||||||
) -> MyResponse {
|
) -> MyResponse {
|
||||||
|
if query.is_invalid() {
|
||||||
|
return MyResponse::bad_request_plain(describe_query_error(&i18n, &query));
|
||||||
|
}
|
||||||
|
|
||||||
let fp = if let Some(fp) = db.lookup_primary_fingerprint(&query) {
|
let fp = if let Some(fp) = db.lookup_primary_fingerprint(&query) {
|
||||||
fp
|
fp
|
||||||
} else {
|
} else {
|
||||||
|
@ -979,13 +983,13 @@ pub mod tests {
|
||||||
fn search_invalid() {
|
fn search_invalid() {
|
||||||
let (_tmpdir, client) = client().unwrap();
|
let (_tmpdir, client) = client().unwrap();
|
||||||
check_response(&client, "/search?q=0x1234abcd",
|
check_response(&client, "/search?q=0x1234abcd",
|
||||||
Status::BadRequest, "not supported, sorry!");
|
Status::BadRequest, "not supported");
|
||||||
check_response(&client, "/search?q=1234abcd",
|
check_response(&client, "/search?q=1234abcd",
|
||||||
Status::BadRequest, "not supported, sorry!");
|
Status::BadRequest, "not supported");
|
||||||
check_response(&client, "/pks/lookup?op=get&search=0x1234abcd",
|
check_response(&client, "/pks/lookup?op=get&search=0x1234abcd",
|
||||||
Status::BadRequest, "not supported, sorry!");
|
Status::BadRequest, "not supported");
|
||||||
check_response(&client, "/pks/lookup?op=get&search=1234abcd",
|
check_response(&client, "/pks/lookup?op=get&search=1234abcd",
|
||||||
Status::BadRequest, "not supported, sorry!");
|
Status::BadRequest, "not supported");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -243,6 +243,8 @@ fn key_to_response(
|
||||||
) -> MyResponse {
|
) -> MyResponse {
|
||||||
let fp = if let Some(fp) = db.lookup_primary_fingerprint(&query) {
|
let fp = if let Some(fp) = db.lookup_primary_fingerprint(&query) {
|
||||||
fp
|
fp
|
||||||
|
} else if query.is_invalid() {
|
||||||
|
return MyResponse::bad_request("index", anyhow!(describe_query_error(&i18n, &query)));
|
||||||
} else {
|
} else {
|
||||||
return MyResponse::not_found(None, describe_query_error(&i18n, &query));
|
return MyResponse::not_found(None, describe_query_error(&i18n, &query));
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue