lib/egregious.rb in egregious-0.2.2 vs lib/egregious.rb in egregious-0.2.3
- old
+ new
@@ -73,10 +73,27 @@
ActiveRecord::RecordInvalid=>status_code(:bad_request),
ActiveRecord::RecordNotFound=>status_code(:not_found),
ActiveRecord::UnknownAttributeError=>status_code(:bad_request)
})
end
+
+ if defined?(Mongoid)
+ require 'egregious/extensions/mongoid'
+
+ exception_codes.merge!({
+ Mongoid::Errors::InvalidFind=>status_code(:bad_request),
+ Mongoid::Errors::DocumentNotFound=>status_code(:not_found),
+ Mongoid::Errors::Validations=>status_code(:unprocessable_entity)
+ })
+
+ if Mongoid::VERSION > '3'
+ exception_codes.merge!({
+ Mongoid::Errors::ReadonlyAttribute=>status_code(:forbidden),
+ Mongoid::Errors::UnknownAttribute=>status_code(:bad_request)
+ })
+ end
+ end
if defined?(Warden)
exception_codes.merge!({
Warden::NotAuthenticated=>status_code(:unauthorized),
})
@@ -90,10 +107,10 @@
@@exception_codes = exception_codes
end
@@exception_codes = self._load_exception_codes
- @@root = defined?(Rail) ? Rails.root : nil
+ @@root = defined?(Rails) ? Rails.root : nil
# exposes the root of the app
def self.root
@@root
end