-
Notifications
You must be signed in to change notification settings - Fork 17
Open
Description
When using conjure generated clients, any error is represented by a generic ConjureHTTPException that requires manual parsing to determine exactly what the error is. If I have some conjure error
SomeException:
docs: Something went wrong
code: INVALID_ARGUMENT
namespace: MyService
safe-args:
argument: string
object: SomeObjectWithFields
unsafe-args:
unsafeArgument: string I would like to get some generated python exception
class SomeException(Exception):
"""
Something went wrong
"""
NAMESPACE = "MyService"
ERROR_CODE = "INVALID_ARGUMENT" # probably want this to be an enum
ERROR_NAME = "MyService:SomeException"
def __init__(self, conjure_exception: ConjureHTTPError):
# do some validation
self.unsafe_args = ...
self.safe_args = ...
@staticmethod
def is_instance(self, conjure_exception: ConjureHTTPError) -> bool:
# check if the conjure exception is this
return conjure_exception.error_name == SomeException.ERROR_NAMEThat way I can use this in my code to convert a ConjureHTTPError into a more user friendly exception, with some actual types
try:
return some_service.endpoint()
except ConjureHTTPError as err:
if SomeException.is_error(err):
actual_exception = SomeException(err)
raise UserFriendlyError(actual_exception.safe_args.argument, actual_exception.object.some_object_field)
# maybe check some other exceptions here too
raise errBoth java and typescript conjure clients do this, I think it would be really useful to have it in python as well
Metadata
Metadata
Assignees
Labels
No labels