Token handler: print a relevant error message.

This commit is contained in:
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) 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
# #

View File

@ -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|
pp! context.request.headers["Host"] ip = case addr
ip = context.request.headers["Host"] rescue next 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 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
context.response.print "; Success!" # 🔻 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 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!" # ⚠