-
Notifications
You must be signed in to change notification settings - Fork 24
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 Metadata instead of raising TypeError on invalid requests #38
Comments
There is a workaround for this -- ignoring errors with |
Hi @ctdunc , I'm happy to accept a PR on this, open to suggestions. My initial thoughts are we would want to introduce a single error type like the one below and replace a subset of the TypeErrors with it.
Admitted there are a few different error types here,
I think treating these separately is maybe a bit of over engineering though, but happy to hear if you have a use case for this. On your last point and embedding meta data in the error, what were you thinking? Maybe something like
and then the request and the response can be passed into the exception as args, which will also allow them to be accesses later by user specific error handling code. |
Hi Matthew---thanks for responding! class BlpParseError(Exception):
def __str__(self):
return f"Parsing error occurred with request {self.args[0]} and response {self.args[1]}"
@property
def error_response(self):
#obviously this would return the actual error message & not just my copy/pasted output
return {{'securityError': {'source': '****', 'code': 43, 'category': 'BAD_SEC', 'message': 'Unknown/Invalid Security [nid:24978]', 'subcategory': 'INVALID_SECURITY'}} where we can handle the response without looking at the string representation of the error. As for the different error types, I actually do think it may be a good idea to subclass different error types here. E.g. for unrecognized/unwrapped fields, we may want to raise a NotImplementedError. In the situation of invalid security ids/other bad arguments, a ValueError might be more descriptive, since we did submit a query of valid (string) type, but with a bad value, & raise a TypeError for bulk vs reference data, since the logic in handling these may be different. |
Okay sure that sounds reasonable. If you want to submit a PR implementing this functionality I'd be happy to review it. |
Code Sample, a copy-pastable example if possible
Problem description
We have a workflow which sometimes places expired security identifiers into blp requests. Generic TypeErrors do not return enough information for us to handle them well without writing logic to parse error messages across the codebase.
Expected Output
It would be great if it returned this securityError as a dict or object so that we may handle it gracefully by dropping the security & retrying the request. On a larger scale, it would be an improvement to allow for more graceful error handling by returning/raising error objects with more metadata.
Happy to work on a PR with changes if this is something you're interested in implementing.
The text was updated successfully, but these errors were encountered: