Libcloud
  1. Libcloud
  2. LIBCLOUD-114

Provider HTTP Error responses need to be propagated in a better way.

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Core
    • Labels:
      None

      Description

      Currently when a provider returns an unexpected (error) response the response code and message must be parsed from a message string in a base Exception. Instead we should include the error code and error message in an exception class (ProviderHTTPResponseError).

        Activity

        Hide
        Tomaz Muraus added a comment - - edited

        Can you provide a concreate example please?

        You should be able to handle cases like this in a custom Response class.

        Show
        Tomaz Muraus added a comment - - edited Can you provide a concreate example please? You should be able to handle cases like this in a custom Response class.
        Hide
        Brian Hoenig added a comment -

        Sure, this is to handle and response from a provider that fails the drivers success test.

        A good example is attempting to save an image on a node that is busy:
        ------------------
        In [8]: lcProvider.ex_save_image(lcNode,'spam')
        Out[8]: <NodeImage: id=10246636, name=spam, driver=Rackspace (UK) ...>

        In [9]: lcProvider.ex_save_image(lcNode,'spam')

        ......
        Exception: 400 Bad Request 422 Unprocessable Entity: Cannot create a new backup request while saving a prior backup or migrating.; com.rackspace.cloud.service.servers.CloudServersFault: Fault occured
        ---------------------

        The response information is valuable and has to be parsed from a string, and that string is currently constructed differently for every provider. It would be nice for the caller to get that code in a uniform way across providers. I understand that this can be handled with a custom response class (and is for auth errors in a variety of ways for some providers), but it would be much more useful and keep things more consistent to propagate the provider response. The new exception class would allow things like this:

        --------------------------

        In [18]: try:
        ....: lcNode.id = "23676"
        ....: lcProvider.ex_save_image(lcNode,'spam')
        ....: except ProviderHTTPResponseError, e:
        ....: print str(e)
        ....: print
        ....: print "Code: %s" % e.http_error_code
        ....: print
        ....: print "Message: %s" % e.http_error_message
        ....:

        404 Not Found Not Found; com.rackspace.cloud.service.servers.ItemNotFoundFault: Not Found

        Code: 404

        Message: Not Found

        -----------------------

        Show
        Brian Hoenig added a comment - Sure, this is to handle and response from a provider that fails the drivers success test. A good example is attempting to save an image on a node that is busy: ------------------ In [8] : lcProvider.ex_save_image(lcNode,'spam') Out [8] : <NodeImage: id=10246636, name=spam, driver=Rackspace (UK) ...> In [9] : lcProvider.ex_save_image(lcNode,'spam') ...... Exception: 400 Bad Request 422 Unprocessable Entity: Cannot create a new backup request while saving a prior backup or migrating.; com.rackspace.cloud.service.servers.CloudServersFault: Fault occured --------------------- The response information is valuable and has to be parsed from a string, and that string is currently constructed differently for every provider. It would be nice for the caller to get that code in a uniform way across providers. I understand that this can be handled with a custom response class (and is for auth errors in a variety of ways for some providers), but it would be much more useful and keep things more consistent to propagate the provider response. The new exception class would allow things like this: -------------------------- In [18] : try: ....: lcNode.id = "23676" ....: lcProvider.ex_save_image(lcNode,'spam') ....: except ProviderHTTPResponseError, e: ....: print str(e) ....: print ....: print "Code: %s" % e.http_error_code ....: print ....: print "Message: %s" % e.http_error_message ....: 404 Not Found Not Found; com.rackspace.cloud.service.servers.ItemNotFoundFault: Not Found Code: 404 Message: Not Found -----------------------

          People

          • Assignee:
            Unassigned
            Reporter:
            Brian Hoenig
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:

              Time Tracking

              Estimated:
              Original Estimate - 24h
              24h
              Remaining:
              Remaining Estimate - 24h
              24h
              Logged:
              Time Spent - Not Specified
              Not Specified

                Development