From 12ba29dc0359869f9644ae22a761016df0f6eb59 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Fri, 25 Oct 2019 20:47:21 -0700 Subject: [PATCH] improve project server 404 error message --- pollen/private/project-server-routes.rkt | 14 ++++++++++---- pollen/private/ts.rktd | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/pollen/private/project-server-routes.rkt b/pollen/private/project-server-routes.rkt index 271181c..ec1c19d 100644 --- a/pollen/private/project-server-routes.rkt +++ b/pollen/private/project-server-routes.rkt @@ -176,7 +176,7 @@ null))) (define dirlinks (cons "/" (map (λ (ps) (format "/~a/" (apply build-path ps))) (for/list ([i (in-range (length (cdr dirs)))]) - (take (cdr dirs) (add1 i)))))) + (take (cdr dirs) (add1 i)))))) `(row (heading ((colspan "3")) ,@(add-between (map (λ (dir dirlink) `(a ((href ,(format "~a~a" dirlink (setup:main-pagetree)))) ,(->string dir))) dirs dirlinks) "/")))) (define (make-path-row filename source indent-level) @@ -301,15 +301,21 @@ [possible-idx-path (in-value (build-path index-dir possible-idx-page))] [_ (in-value (render-from-source-or-output-path possible-idx-path))] #:when (file-exists? possible-idx-path)) - (redirect-to (path->string (find-relative-path index-dir possible-idx-path)) temporarily)) + (redirect-to (path->string (find-relative-path index-dir possible-idx-path)) temporarily)) (route-404 req))) ;; 404 route (define/contract (route-404 req) (request? . -> . response?) + (define missing-url (url->string (request-uri req))) (define missing-path-string (path->string (simplify-path (req->path req)))) - (message (format "can't find ~a" missing-path-string)) + (message (format "can't find ~a" missing-url)) (response/xexpr+doctype `(html (head (title "404 error") (link ((href "/error.css") (rel "stylesheet")))) - (body (div ((class "section")) (div ((class "title")) "404 error") (p ,(format "~v" missing-path-string) " was not found")))))) + (body (div ((class "section")) + (div ((class "title")) "404 error") + (p ,(format "URL ~v was not found at path ~v" missing-url + (match missing-path-string + [(regexp #rx"/$") (string-append missing-path-string "index.html")] + [mps mps])))))))) diff --git a/pollen/private/ts.rktd b/pollen/private/ts.rktd index b92d1ca..fdfd6d4 100644 --- a/pollen/private/ts.rktd +++ b/pollen/private/ts.rktd @@ -1 +1 @@ -1570719309 +1572061641