Skip to content

Conversation

@jbabac
Copy link
Contributor

@jbabac jbabac commented Feb 19, 2025

No description provided.

@jbabac jbabac self-assigned this Feb 19, 2025
from datetime import datetime, timedelta, timezone
from hashlib import sha1, sha256, md5
from hmac import new as hmac
from types import GeneratorType
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should use the typing.Generator to add type hinting as I think this GeneratorType is use to check if the object is a generator type object.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed already.

def response(self) -> Generator:
status_code = None
while status_code != 200:
resp_data = super().response()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can directly call the self.data() and override it here in the subclass, and remove the special handling case in the data() in the base class, to isolate the feeds results, as the response path is not actually being used for feeds as the results is always a text not a json/dict. wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion I would like to have it as is. why? because I want it to undergo the same processes as the normal endpoint would take (e.g. checking the limit exceeded, retry action, rate limiting checking, etc.) If we would override the self.data() method we would still need those processes to be implemented as well causing code duplication. what are your thoughts about it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah make sense, hmm I think not actually code duplication rather code isolation for single responsibility, we don't want to put too much if-else condition if there will be another products in the future to support different kinds of results.

also side note: I think we can move the raise condition inside check_limit_exceeded so we dont have the 'code duplication' in the async request as it will automatically handle the ServiceException.

Checking the async request, it seems it doesn't raise the 503 exception unless it returns the actual 503 status code and it will be catched in the setStatus which returns a different exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed already.

)

def domaindiscovery(self, **kwargs):
def domaindiscovery(self, **kwargs) -> FeedsResults:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

if isinstance(self._data, dict) and (
"response" in self._data and "limit_exceeded" in self._data["response"] and self._data["response"]["limit_exceeded"] is True
):
raise ServiceException(503, f"Limit Exceeded: {self._data['response']['message']}")
Copy link
Contributor

@briluza briluza Feb 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we could move it in the end of condition?

limit_exceeded, reason = False, "Limit Exceeded"

if limit_exceeded:
raise ServiceException(503, reason)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed already.

return self._data

def check_limit_exceeded(self):
limit_exceeded, reason = False, ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a pedantic change:

can we put the Limit Exceeded as default reason? so we dont need to define it in elif and just concat the message in the if statement.

Overall, LGTM ✅ . Nice!!

Copy link
Contributor

@briluza briluza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job @jbabac ! LGTM ✅

@jbabac jbabac merged commit 50b8b84 into 2.3 Feb 20, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants