Token handler: print a relevant error message.
This commit is contained in:
parent
a6272b3873
commit
f63eff59a8
@ -147,9 +147,7 @@ class DNSManager::Client < IPC
|
|||||||
def use_token(token_uuid : String, address : String)
|
def use_token(token_uuid : String, address : String)
|
||||||
request = Request::UseToken.new token_uuid, address
|
request = Request::UseToken.new token_uuid, address
|
||||||
send_now request
|
send_now request
|
||||||
response = parse_message [ Response::Success ], read
|
parse_message [ Response::Success ], read
|
||||||
raise "token update failed" unless response.class == Response::Success
|
|
||||||
response
|
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -13,8 +13,14 @@ dnsmanagerd = DNSManager::Client.new
|
|||||||
#dnsmanagerd.login login, pass
|
#dnsmanagerd.login login, pass
|
||||||
|
|
||||||
server = HTTP::Server.new do |context|
|
server = HTTP::Server.new do |context|
|
||||||
|
ip = case addr
|
||||||
|
when "127.0.0.1"
|
||||||
|
pp! context.request.remote_address
|
||||||
|
context.request.remote_address.not_nil!.to_s
|
||||||
|
else
|
||||||
pp! context.request.headers["Host"]
|
pp! context.request.headers["Host"]
|
||||||
ip = context.request.headers["Host"] rescue next
|
context.request.headers["Host"] rescue next
|
||||||
|
end
|
||||||
|
|
||||||
case context.request.path
|
case context.request.path
|
||||||
when /^\/token-update\/(?<token>[a-z0-9-]+)/
|
when /^\/token-update\/(?<token>[a-z0-9-]+)/
|
||||||
@ -26,8 +32,14 @@ server = HTTP::Server.new do |context|
|
|||||||
context.response.content_type = "text/html"
|
context.response.content_type = "text/html"
|
||||||
context.response.print "coucou, token: #{token} from #{ip}"
|
context.response.print "coucou, token: #{token} from #{ip}"
|
||||||
begin
|
begin
|
||||||
dnsmanagerd.use_token token, ip
|
response = dnsmanagerd.use_token token, ip
|
||||||
|
case response
|
||||||
|
when DNSManager::Response::Success
|
||||||
context.response.print "; Success!" # 🔻
|
context.response.print "; Success!" # 🔻
|
||||||
|
when DNSManager::Response::Error
|
||||||
|
puts "error while updating token: #{response.reason}"
|
||||||
|
context.response.print "; command failed: #{response.reason}" # ⚠
|
||||||
|
end
|
||||||
rescue e
|
rescue e
|
||||||
puts "error while updating token: #{e}"
|
puts "error while updating token: #{e}"
|
||||||
context.response.print "; The command failed!" # ⚠
|
context.response.print "; The command failed!" # ⚠
|
||||||
|
Loading…
Reference in New Issue
Block a user