Improved error handling.
This commit is contained in:
parent
fcdf62cd13
commit
30b05bd991
2 changed files with 35 additions and 11 deletions
|
@ -5,11 +5,11 @@ class Integration::SipgateController < ApplicationController
|
||||||
|
|
||||||
# notify about inbound call / block inbound call
|
# notify about inbound call / block inbound call
|
||||||
def in
|
def in
|
||||||
return if feature_disabled
|
return if !configured?
|
||||||
|
|
||||||
config = Setting.get('sipgate_config')
|
config = Setting.get('sipgate_config')
|
||||||
config_inbound = config[:inbound]
|
config_inbound = config[:inbound] || {}
|
||||||
block_caller_ids = config_inbound[:block_caller_ids]
|
block_caller_ids = config_inbound[:block_caller_ids] || []
|
||||||
|
|
||||||
if params['event'] == 'newCall'
|
if params['event'] == 'newCall'
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ class Integration::SipgateController < ApplicationController
|
||||||
|
|
||||||
# set caller id of outbound call
|
# set caller id of outbound call
|
||||||
def out
|
def out
|
||||||
return if feature_disabled
|
return if !configured?
|
||||||
|
|
||||||
config = Setting.get('sipgate_config')
|
config = Setting.get('sipgate_config')
|
||||||
config_outbound = config[:outbound][:routing_table]
|
config_outbound = config[:outbound][:routing_table]
|
||||||
|
@ -91,15 +91,26 @@ class Integration::SipgateController < ApplicationController
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def feature_disabled
|
def configured?
|
||||||
if !Setting.get('sipgate_integration')
|
if !Setting.get('sipgate_integration')
|
||||||
render(
|
xml_error('Feature is disable, please contact your admin to enable it!')
|
||||||
json: {},
|
return false
|
||||||
status: :unauthorized
|
|
||||||
)
|
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
false
|
config = Setting.get('sipgate_config')
|
||||||
|
if !config || !config[:inbound] || !config[:outbound]
|
||||||
|
xml_error('Feature not configured, please contact your admin!')
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
def xml_error(error)
|
||||||
|
xml = Builder::XmlMarkup.new(indent: 2)
|
||||||
|
xml.instruct!
|
||||||
|
content = xml.Response() do
|
||||||
|
xml.Error(error)
|
||||||
|
end
|
||||||
|
send_data content, type: 'application/xml; charset=UTF-8;', status: '500'
|
||||||
end
|
end
|
||||||
|
|
||||||
def base_url
|
def base_url
|
||||||
|
|
|
@ -179,6 +179,19 @@ class SipgateControllerTest < ActionDispatch::IntegrationTest
|
||||||
assert_equal('http://zammad.example.com/api/v1/sipgate/in', on_hangup)
|
assert_equal('http://zammad.example.com/api/v1/sipgate/in', on_hangup)
|
||||||
assert_equal('http://zammad.example.com/api/v1/sipgate/in', on_answer)
|
assert_equal('http://zammad.example.com/api/v1/sipgate/in', on_answer)
|
||||||
|
|
||||||
|
# no config
|
||||||
|
Setting.set('sipgate_config', {})
|
||||||
|
params = 'event=newCall&direction=in&from=4912347114711&to=4930600000000&callId=4991155921769858278&user%5B%5D=user+1&user%5B%5D=user+2'
|
||||||
|
post '/api/v1/sipgate/in', params
|
||||||
|
assert_response(500)
|
||||||
|
error = nil
|
||||||
|
content = @response.body
|
||||||
|
response = REXML::Document.new(content)
|
||||||
|
response.elements.each('Response/Error') do |element|
|
||||||
|
error = element.text
|
||||||
|
end
|
||||||
|
assert_equal('Feature not configured, please contact your admin!', error)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue