Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
robertbastian committed Jul 2, 2024
1 parent d81590c commit da366bd
Showing 1 changed file with 32 additions and 35 deletions.
67 changes: 32 additions & 35 deletions provider/adapters/src/fallback/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,49 +193,46 @@ impl<P> LocaleFallbackProvider<P> {
&self,
marker: DataMarkerInfo,
mut base_req: DataRequest,
mut f1: F1,
mut f2: F2,
mut load: F1,
mut access_response_metadata: F2,
) -> Result<R, DataError>
where
F1: FnMut(DataRequest) -> Result<R, DataError>,
F2: FnMut(&mut R) -> &mut DataResponseMetadata,
{
if marker.is_singleton {
return f1(base_req);
}
let mut fallback_iterator = self
.fallbacker
.for_config(marker.fallback_config)
.fallback_for(base_req.id.locale.clone());
let base_silent = core::mem::replace(&mut base_req.metadata.silent, true);
loop {
let result = f1(DataRequest {
id: DataIdentifierBorrowed::for_marker_attributes_and_locale(
base_req.id.marker_attributes,
fallback_iterator.get(),
),
..base_req
});
if !result_is_err_missing_locale(&result) {
return result
.map(|mut res| {
f2(&mut res).locale = Some(fallback_iterator.take());
res
})
// Log the original request rather than the fallback request
.map_err(|e| {
base_req.metadata.silent = base_silent;
e.with_req(marker, base_req)
});
}
// If we just checked und, break out of the loop.
if fallback_iterator.get().is_und() {
break;

let mut response = load(base_req);
if result_is_err_missing_locale(&response) {
let mut fallback_iterator = self
.fallbacker
.for_config(marker.fallback_config)
.fallback_for(base_req.id.locale.clone());
while result_is_err_missing_locale(&response) {
response = load(DataRequest {
id: DataIdentifierBorrowed::for_marker_attributes_and_locale(
base_req.id.marker_attributes,
fallback_iterator.get(),
),
..base_req
})
.map(|mut res| {
access_response_metadata(&mut res).locale = Some(fallback_iterator.take());
res
});
// If we just checked und, break out of the loop.
if fallback_iterator.get().is_und() {
response = Err(DataErrorKind::IdentifierNotFound.with_req(marker, base_req));
}
fallback_iterator.step();
}
fallback_iterator.step();
}
base_req.metadata.silent = base_silent;
Err(DataErrorKind::IdentifierNotFound.with_req(marker, base_req))

// Log the original request rather than the fallback request
response.map_err(|e| {
base_req.metadata.silent = base_silent;
e.with_req(marker, base_req)
})
}
}

Expand Down

0 comments on commit da366bd

Please sign in to comment.