improve error handling
authorTom Clegg <tom@clinicalfuture.com>
Fri, 11 Jan 2013 07:27:10 +0000 (23:27 -0800)
committerTom Clegg <tom@clinicalfuture.com>
Fri, 11 Jan 2013 07:27:10 +0000 (23:27 -0800)
app/controllers/application_controller.rb

index f080ae14b6490d809a48e3aa998fbb812bb5061d..5b88277ac9fb687115aa3e61d39d9ce5d27bf20a 100644 (file)
@@ -16,8 +16,13 @@ class ApplicationController < ActionController::Base
     :with => :render_not_found
   end
 
-  def render_error
-    render json: { errors: @object.errors.full_messages }, status: 422
+  def render_error(e)
+    if @object and @object.errors and @object.errors.full_messages
+      errors = @object.errors.full_messages
+    else
+      errors = [e.inspect]
+    end
+    render json: { errors: errors }, status: 422
   end
 
   def render_not_found