i'm using third party api emits httperror.
by catching error can inspect http response status , narrow down problem. emit more specific httperror i'll dub backenderror , ratelimiterror. latter has context variables added.
how create custom exception inherits httperror , can created without losing original exception?
the question polymorphism 101 head fuzzy today:
class backenderror(httperror): """the google api having it's own issues""" def __init__(self, ex): # super doesn't seem right because have # exception. surely don't need extract # relevant bits ex , call __init__ again?! # self = ex # doesn't feel right either try: stuff() except httperror ex: if ex.resp.status == 500: raise backenderror(ex) how catch original httperror , encapsulate still recognisable both httperror , backenderror?
if @ actual definition of googleapiclient.errors.httperror,
__init__(self, resp, content, uri=none) so, after inheriting need initialize base class values.
class backenderror(httperror): """the google api having it's own issues""" def __init__(self, resp, content, uri=none): # invoke super class's __init__ super(backenderror, self).__init__(resp, content, uri) # customization can done here and when catch error,
except httperror ex: if ex.resp.status == 500: raise backenderror(ex.resp, ex.content, ex.uri) if don't want client explicitly unpack contents, can accept httperror object in backenderror's __init__ , can unpacking, this
class backenderror(httperror): """the google api having it's own issues""" def __init__(self, ex): # invoke super class's __init__ super(backenderror, self).__init__(ex.resp, ex.content, ex.uri) # customization can done here and can do
except httperror ex: if ex.resp.status == 500: raise backenderror(ex)