3200: Improve error handling in Workbench's API client.
authorBrett Smith <brett@curoverse.com>
Wed, 23 Jul 2014 20:50:18 +0000 (16:50 -0400)
committerBrett Smith <brett@curoverse.com>
Thu, 24 Jul 2014 14:58:45 +0000 (10:58 -0400)
* Fix the class used for error responses that can be parsed but don't
  have a dedicated subclass.

* Ensure that exception.api_response[:errors] is always an array.

This improves the error reporting for #3207.

apps/workbench/app/models/arvados_api_client.rb

index 9f34a29e5bfffb2c5df33299cb9b3b0181509681..78d3beef3c216161196c6451544c83ce5fbcc181 100644 (file)
@@ -8,6 +8,10 @@ class ArvadosApiClient
     def initialize(request_url, errmsg)
       @request_url = request_url
       @api_response ||= {}
+      errors = @api_response[:errors]
+      if not errors.is_a?(Array)
+        @api_response[:errors] = [errors || errmsg]
+      end
       super(errmsg)
     end
   end
@@ -138,7 +142,8 @@ class ArvadosApiClient
     if not resp.is_a? Hash
       raise InvalidApiResponseException.new(url, msg)
     elsif msg.status_code != 200
-      error_class = ERROR_CODE_CLASSES.fetch(msg.status_code, ApiError)
+      error_class = ERROR_CODE_CLASSES.fetch(msg.status_code,
+                                             ApiErrorResponseException)
       raise error_class.new(url, msg)
     end