diff --git a/src/sunstone/public/js/plugins/support-tab.js b/src/sunstone/public/js/plugins/support-tab.js index 5373649d54..a720cbc655 100644 --- a/src/sunstone/public/js/plugins/support-tab.js +++ b/src/sunstone/public/js/plugins/support-tab.js @@ -118,10 +118,14 @@ var support_actions = { //addTemplateElement(request, response); //notifyCustom(tr("Request created"), " ID: " + response.VMTEMPLATE.ID, false) }, - error: function(request, response){ + error: function(request, error_json){ popFormDialog("create_support_request_form", $("#support-tab")); - $("a[href=back]", $("#support-tab")).trigger("click"); - show_support_connect(); + if (error_json.error.http_status=="403") { + notifyError(error_json.error.message); + } else { + $("a[href=back]", $("#support-tab")).trigger("click"); + show_support_connect(); + } } }, diff --git a/src/sunstone/routes/support.rb b/src/sunstone/routes/support.rb index 0753987ba0..8e6ea6affc 100644 --- a/src/sunstone/routes/support.rb +++ b/src/sunstone/routes/support.rb @@ -161,16 +161,22 @@ post '/support/request' do check_zendesk_api_gem body_hash = JSON.parse(@request_body) - zrequest = zendesk_client.requests.create({ - :subject => body_hash['subject'], - :comment => { :value => body_hash['description'] }, - :custom_fields => [ - {:id => 391197, :value => body_hash['severity']}, - {:id => 391130, :value => body_hash['opennebula_version']} - ] - }) - [201, JSON.pretty_generate(zrequest_to_one(zrequest))] + zrequest = ticket = ZendeskAPI::Request.new(zendesk_client, { + :subject => body_hash['subject'], + :comment => { :value => body_hash['description'] }, + :custom_fields => [ + {:id => 391197, :value => body_hash['severity']}, + {:id => 391130, :value => body_hash['opennebula_version']} + ] + }) + + if zrequest.save + [201, JSON.pretty_generate(zrequest_to_one(zrequest))] + else + logger.error(zrequest.errors) + [403, Error.new(zrequest.errors["base"][0]["description"]).to_json] + end end post '/support/request/:id/action' do