added rescue for urls that don't resolve

pull/22/head
Adam Townsend 2023-10-12 19:03:03 -07:00
parent bbb710a5e1
commit c81a7a6160
1 changed files with 3 additions and 1 deletions

4
app.rb
View File

@ -69,9 +69,11 @@ class App < Roda
rescue OpenURI::HTTPError rescue OpenURI::HTTPError
response.status = 400 response.status = 400
return {message: "url not found"}.to_json return {message: "url not found"}.to_json
rescue SocketError => e
response.status = 400
return {message: "url does not resolve"}.to_json
end end
if links.filter(:url => url).first.nil? if links.filter(:url => url).first.nil?
code = SecureRandom.urlsafe_base64 4 code = SecureRandom.urlsafe_base64 4
links.insert(url: url, code: code) links.insert(url: url, code: code)