diff --git a/api/axis.py b/api/axis.py index 3ef0d210ab..38d2edcd32 100644 --- a/api/axis.py +++ b/api/axis.py @@ -1703,7 +1703,8 @@ def _parse(self, parsed: dict[str, Any], **kwargs: Any) -> T: class Axis360FulfillmentInfoResponseParser( JSONResponseParser[ tuple[Union[FindawayManifest, "AxisNowManifest"], datetime.datetime] - ] + ], + LoggerMixin, ): """Parse JSON documents into Findaway audiobook manifests or AxisNow manifests.""" @@ -1771,6 +1772,19 @@ def parse_findaway( sessionKey = k("FNDSessionKey", parsed) checkoutId = k("FNDTransactionID", parsed) + if sessionKey == "Expired": + if license_pool.identifier is None: + identifier = f"LicensePool {license_pool.id}" + else: + identifier = f"{license_pool.identifier.type}/{license_pool.identifier.identifier}" + + message = f"Expired findaway session key for {identifier}. Request data: {json.dumps(parsed)}" + self.log.error(message) + raise RemoteInitiatedServerError( + message, + self.SERVICE_NAME, + ) + # Acquire the TOC information metadata_response = self.api.get_audiobook_metadata(fulfillmentId) parser = AudiobookMetadataParser() diff --git a/tests/api/test_axis.py b/tests/api/test_axis.py index dd25b36d2e..97c5df94b1 100644 --- a/tests/api/test_axis.py +++ b/tests/api/test_axis.py @@ -1639,6 +1639,13 @@ def get_data(): m(bad_date, license_pool=pool) assert "Could not parse expiration date: not-a-date" in str(excinfo.value) + # Try with an expired session key. + expired_session_key = get_data() + expired_session_key["FNDSessionKey"] = "Expired" + with pytest.raises(RemoteInitiatedServerError) as excinfo: + m(expired_session_key, license_pool=pool) + assert "Expired findaway session key" in str(excinfo.value) + def test__parse_axisnow(self, axis360parsers: Axis360FixturePlusParsers) -> None: # _parse will create a valid AxisNowManifest given a # complete document.