Skip to content

Commit

Permalink
return an empty result when geolocation data is not found (fastly#341)
Browse files Browse the repository at this point in the history
  • Loading branch information
joeshaw authored and cmckendry committed Feb 8, 2024
1 parent b8ba368 commit 0b77b7c
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 30 deletions.
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

0 comments on commit 0b77b7c

Please sign in to comment.