From f8499a79c2c8cd6b5e495886dc436010945bd55a Mon Sep 17 00:00:00 2001 From: Adam Townsend Date: Sat, 7 Oct 2023 13:38:10 -0700 Subject: [PATCH] check if the link exists, redirects home if it doesn't --- app.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app.rb b/app.rb index 54554b6..44dae4c 100644 --- a/app.rb +++ b/app.rb @@ -18,8 +18,12 @@ class App < Roda end r.get String do | url_code | - link = links.filter(:code => url_code).first[:url] - r.redirect link + link = links.filter(:code => url_code) + if link.first.nil? + flash['message'] = "Link #{url_code} doesn't exist" + r.redirect '/' + end + r.redirect link.first[:url] end r.post "create" do