Return-Path: X-Original-To: apmail-deltacloud-dev-archive@www.apache.org Delivered-To: apmail-deltacloud-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 37F42DD9B for ; Thu, 7 Feb 2013 12:53:28 +0000 (UTC) Received: (qmail 75390 invoked by uid 500); 7 Feb 2013 12:53:28 -0000 Delivered-To: apmail-deltacloud-dev-archive@deltacloud.apache.org Received: (qmail 75333 invoked by uid 500); 7 Feb 2013 12:53:27 -0000 Mailing-List: contact dev-help@deltacloud.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@deltacloud.apache.org Delivered-To: mailing list dev@deltacloud.apache.org Received: (qmail 75158 invoked by uid 99); 7 Feb 2013 12:53:26 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Feb 2013 12:53:26 +0000 X-ASF-Spam-Status: No, hits=-5.0 required=5.0 tests=RCVD_IN_DNSWL_HI,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of mfojtik@redhat.com designates 209.132.183.28 as permitted sender) Received: from [209.132.183.28] (HELO mx1.redhat.com) (209.132.183.28) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Feb 2013 12:53:19 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r17CqxHE025950 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 7 Feb 2013 07:52:59 -0500 Received: from boosh.local.com (dhcp-29-235.brq.redhat.com [10.34.29.235]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r17CquTD001508 for ; Thu, 7 Feb 2013 07:52:58 -0500 From: mfojtik@redhat.com To: dev@deltacloud.apache.org Subject: [PATCH core 2/4] CIMI: Capture the validation errors and advertise them as HTTP 400 Date: Thu, 7 Feb 2013 13:52:51 +0100 Message-Id: <1360241573-13304-3-git-send-email-mfojtik@redhat.com> In-Reply-To: <1360241573-13304-1-git-send-email-mfojtik@redhat.com> References: <1360241573-13304-1-git-send-email-mfojtik@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-Virus-Checked: Checked by ClamAV on apache.org From: Michal Fojtik 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 --- 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