Token handler: print a relevant error message.

master
Philippe Pittoli 2024-03-31 17:45:43 +02:00
parent a6272b3873
commit f63eff59a8
2 changed files with 17 additions and 7 deletions

View File

@ -147,9 +147,7 @@ class DNSManager::Client < IPC
def use_token(token_uuid : String, address : String)
request = Request::UseToken.new token_uuid, address
send_now request
response = parse_message [ Response::Success ], read
raise "token update failed" unless response.class == Response::Success
response
parse_message [ Response::Success ], read
end
#

View File

@ -13,8 +13,14 @@ dnsmanagerd = DNSManager::Client.new
#dnsmanagerd.login login, pass
server = HTTP::Server.new do |context|
pp! context.request.headers["Host"]
ip = context.request.headers["Host"] rescue next
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"]
context.request.headers["Host"] rescue next
end
case context.request.path
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.print "coucou, token: #{token} from #{ip}"
begin
dnsmanagerd.use_token token, ip
context.response.print "; Success!" # 🔻
response = dnsmanagerd.use_token token, ip
case response
when DNSManager::Response::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
puts "error while updating token: #{e}"
context.response.print "; The command failed!" # ⚠