You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by mf...@redhat.com on 2013/02/07 13:52:51 UTC

[PATCH core 2/4] CIMI: Capture the validation errors and advertise them as HTTP 400

From: Michal Fojtik <mf...@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 <mf...@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


Re: [PATCH core 2/4] CIMI: Capture the validation errors and advertise them as HTTP 400

Posted by David Lutterkort <lu...@redhat.com>.
On Thu, 2013-02-07 at 13:52 +0100, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mf...@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.

Heh .. ok; should have looked at all the patches first. That addresses a
lot of what I said about reporting errors. Still, would be nice if we
reported all validation errors in one shot.

David