fix response type for #index
[arvados.git] / services / api / app / controllers / application_controller.rb
index 2e8a11447ca2b92a1868b2abd8c7b25af3d6b169..c80b578adaa69efe1584caeece5fb225b4608d65 100644 (file)
@@ -37,8 +37,11 @@ class ApplicationController < ActionController::Base
   end
 
   def update
-    @object.update_attributes resource_attrs
-    show
+    if @object.update_attributes resource_attrs
+      show
+    else
+      render json: { errors: @object.errors.full_messages }, status: 422
+    end
   end
 
   def destroy
@@ -177,7 +180,10 @@ class ApplicationController < ActionController::Base
       user = nil
       api_client = nil
       api_client_auth = nil
-      supplied_token = params[:api_token] || params[:oauth_token]
+      supplied_token =
+        params[:api_token] ||
+        params[:oauth_token] ||
+        request.headers["Authorization"].andand.match(/OAuth2 ([a-z0-9]+)/).andand[1]
       if supplied_token
         api_client_auth = ApiClientAuthorization.
           includes(:api_client, :user).