Fix Bug where nondefault chod would error

This commit is contained in:
Felisp 2023-12-24 01:21:02 +01:00
parent f392c8f897
commit ed9875c54e

View file

@ -99,16 +99,20 @@
rss-thread-watch.watcher.chod-threads-cache rss-thread-watch.watcher.chod-threads-cache
rss-thread-watch.core.CONFIG" rss-thread-watch.core.CONFIG"
[rqst] [rqst]
(try (let [{{chod :chod :or {chod 60} (try (let [{{chod "chod" :or {chod 60}
:as prms} :params :as prms} :params
uri :uri} rqst uri :uri} rqst
queries (if (vector? (prms "q")) (prms "q") [(prms "q")]) ; to always return vector queries (if (vector? (prms "q")) (prms "q") [(prms "q")]) ; to always return vector
repeat? (prms "repeat") repeat? (prms "repeat")
real-chod (if (or (vector? chod) real-chod (try ;If we can't parse number from give chod param, just use 94
(< chod 60)) (if (or (vector? chod)
94 chod) ;Never accept chod lower that 60 TODO: don't hardcode this (< (Integer/parseInt chod) 60)) ; Never accept chod lower that 60 TODO: don't hardcode this
cache @watcher/chod-threads-cache 94 (Integer/parseInt chod))
] (catch Exception e
94))
cache @watcher/chod-threads-cache]
;; (println "RCVD: " rqst)
(println rqst)
;; ====== Errors ===== ;; ====== Errors =====
;; Something other than feed.xml requested ;; Something other than feed.xml requested
(when-not (s/ends-with? uri "feed.xml") (when-not (s/ends-with? uri "feed.xml")
@ -122,18 +126,18 @@
:body (str "400 You MUST specify query with one OR more'q=searchTerm' url parameter(s)\n\n\n" :body (str "400 You MUST specify query with one OR more'q=searchTerm' url parameter(s)\n\n\n"
"Exmple: '/feed.xml?q=pony&q=IWTCIRD' will show in your feed all threads with 'pony' or 'IWTCIRD'" "Exmple: '/feed.xml?q=pony&q=IWTCIRD' will show in your feed all threads with 'pony' or 'IWTCIRD'"
" in their title that are about to die.")}))) " in their title that are about to die.")})))
;; Whether cache has been generated yet
(when (empty? cache) (when (empty? cache)
(throw (ex-info "503" {:status 503 (throw (ex-info "503" {:status 503
:header {"Content-Type" "text/plain"} :header {"Content-Type" "text/plain"}
:body (str "503 Service Unavailable\n" :body (str "503 Service Unavailable\n"
"Cache is empty, cannot generate feed. Try again later, it may work.")}))) "Cache is empty, cannot generate feed. Try again later, it may work.")})))
;; ==== Everything good ==== ;; ==== Everything good ====
;; (println "RCVD: " rqst) {:status 200
{:status 200 ;; There shouldn't be any problems with this mime type but if there are
;; There shouldn't be any problems with this mime type but if there are ;; replace with "text/xml", or even better, get RSS reader that is not utter shit
;; replace with "text/xml", or even better, get RSS reader that is not utter shit :header {"Content-Type" "application/rss+xml"}
:header {"Content-Type" "application/rss+xml"} :body (generate-feed queries real-chod repeat? cache)})
:body (generate-feed queries real-chod repeat? cache)})
(catch Exception e (catch Exception e
;; Ex-info has been crafted to match HTTP response body so we can send it ;; Ex-info has been crafted to match HTTP response body so we can send it
(if-let [caught (ex-data e)] ;Tam bude ale vždycky ex-data myslím, to chce čekovat jestli t obsahuje nějaký klíč (body? at nemusí být nějaký extra) (if-let [caught (ex-data e)] ;Tam bude ale vždycky ex-data myslím, to chce čekovat jestli t obsahuje nějaký klíč (body? at nemusí být nějaký extra)