deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core 2/4] CIMI: Capture the validation errors and advertise them as HTTP 400
Date Thu, 07 Feb 2013 12:52:51 GMT
From: Michal Fojtik <mfojtik@redhat.com>

In case when client sent scrumbed XML or JSON body, this patch
will make sure we send 'HTTP 400 - Bad Request' back instead of
horrible looking 500 error.

This patch also properly advertise the ValidationError in case
when client want to create CIMI resource but the validation conditions
are not met.

Signed-off-by: Michal fojtik <mfojtik@redhat.com>
---
 server/lib/cimi/collections/base.rb | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/server/lib/cimi/collections/base.rb b/server/lib/cimi/collections/base.rb
index 30c595b..b63fc4d 100644
--- a/server/lib/cimi/collections/base.rb
+++ b/server/lib/cimi/collections/base.rb
@@ -52,6 +52,18 @@ module CIMI::Collections
       report_error
     end
 
+    error CIMI::Model::ValidationError do
+      report_error
+    end
+
+    error JSON::ParserError do
+      report_error(400)
+    end
+
+    error REXML::ParseException do
+      report_error(400)
+    end
+
     before do
       # Respond with 400, If we don't get a http Host header,
       halt 400, "Unable to find HTTP Host header" if @env['HTTP_HOST'] == nil
-- 
1.8.1


Mime
View raw message