Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return an empty result when geolocation data is not found #341

Merged
merged 1 commit into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions lib/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ pub enum Error {
#[error(transparent)]
DeviceDetectionError(#[from] crate::wiggle_abi::DeviceDetectionError),

#[error(transparent)]
GeolocationError(#[from] crate::wiggle_abi::GeolocationError),

#[error(transparent)]
ObjectStoreError(#[from] crate::object_store::ObjectStoreError),

Expand Down Expand Up @@ -184,7 +181,6 @@ impl Error {
// We delegate to some error types' own implementation of `to_fastly_status`.
Error::DictionaryError(e) => e.to_fastly_status(),
Error::DeviceDetectionError(e) => e.to_fastly_status(),
Error::GeolocationError(e) => e.to_fastly_status(),
Error::ObjectStoreError(e) => e.into(),
Error::SecretStoreError(e) => e.into(),
Error::Again => FastlyStatus::Again,
Expand Down
1 change: 0 additions & 1 deletion lib/src/wiggle_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ pub use self::dictionary_impl::DictionaryError;
pub use self::secret_store_impl::SecretStoreError;

pub use self::device_detection_impl::DeviceDetectionError;
pub use self::geo_impl::GeolocationError;

use {
self::{
Expand Down
27 changes: 2 additions & 25 deletions lib/src/wiggle_abi/geo_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,11 @@ use std::{
};

use {
crate::{
error::Error,
session::Session,
wiggle_abi::{fastly_geo::FastlyGeo, types::FastlyStatus},
},
crate::{error::Error, session::Session, wiggle_abi::fastly_geo::FastlyGeo},
std::convert::TryFrom,
wiggle::GuestPtr,
};

#[derive(Debug, thiserror::Error)]
pub enum GeolocationError {
/// Geolocation data for given address not found.
#[error("No geolocation data: {0}")]
NoGeolocationData(String),
}

impl GeolocationError {
/// Convert to an error code representation suitable for passing across the ABI boundary.
pub fn to_fastly_status(&self) -> FastlyStatus {
use GeolocationError::*;
match self {
NoGeolocationData(_) => FastlyStatus::None,
}
}
}

impl FastlyGeo for Session {
fn lookup(
&mut self,
Expand All @@ -57,9 +36,7 @@ impl FastlyGeo for Session {
_ => return Err(Error::InvalidArgument),
};

let result = self
.geolocation_lookup(&ip_addr)
.ok_or_else(|| GeolocationError::NoGeolocationData(ip_addr.to_string()))?;
let result = self.geolocation_lookup(&ip_addr).unwrap_or_default();

if result.len() > buf_len as usize {
return Err(Error::BufferLengthError {
Expand Down