From 1f517f9031e78996dfaf90d9c999b61d065efcbf Mon Sep 17 00:00:00 2001
From: Edward Loveall <edward@edwardloveall.com>
Date: Sun, 13 Feb 2022 10:11:45 -0500
Subject: [PATCH] Link to full Medium URL on error page

Previously the link on the error page was only linking to the path
component of the url, e.g. `/search` but ignoring any query params e.g.
`/search?q=hello`. This uses the HTTP::Request `resource` method which
appears to capture both.
---
 CHANGELOG                            | 1 +
 src/actions/articles/show.cr         | 4 ++--
 src/pages/errors/parse_error_page.cr | 4 ++--
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index e08c01d..035d9ce 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,7 @@
 2022-02-13
 
 * Better article ID parsing
+* Link to full Medium URL on error page
 
 2022-02-12
 
diff --git a/src/actions/articles/show.cr b/src/actions/articles/show.cr
index 7bd1e30..15b65a7 100644
--- a/src/actions/articles/show.cr
+++ b/src/actions/articles/show.cr
@@ -12,8 +12,8 @@ class Articles::Show < BrowserAction
       html(
         Errors::ParseErrorPage,
         message: "Error parsing the URL",
-        status_code: 500,
-        original_path: request.path,
+        status_code: 422,
+        original_resource: request.resource,
       )
     end
   end
diff --git a/src/pages/errors/parse_error_page.cr b/src/pages/errors/parse_error_page.cr
index 5e99ace..2207ec2 100644
--- a/src/pages/errors/parse_error_page.cr
+++ b/src/pages/errors/parse_error_page.cr
@@ -1,7 +1,7 @@
 class Errors::ParseErrorPage < MainLayout
   needs message : String
   needs status_code : Int32
-  needs original_path : String
+  needs original_resource : String
 
   def page_title
     "Error"
@@ -25,7 +25,7 @@ class Errors::ParseErrorPage < MainLayout
       TEXT
       para do
         text "If you like, you can try visiting "
-        a "this page on medium.com", href: "https://medium.com#{original_path}"
+        a "this page on medium.com", href: "https://medium.com#{original_resource}"
       end
     end
   end