diff --git a/src/rss_thread_watch/feed_generator.clj b/src/rss_thread_watch/feed_generator.clj index 761e432..1df60c1 100644 --- a/src/rss_thread_watch/feed_generator.clj +++ b/src/rss_thread_watch/feed_generator.clj @@ -99,16 +99,20 @@ rss-thread-watch.watcher.chod-threads-cache rss-thread-watch.core.CONFIG" [rqst] - (try (let [{{chod :chod :or {chod 60} + (try (let [{{chod "chod" :or {chod 60} :as prms} :params uri :uri} rqst queries (if (vector? (prms "q")) (prms "q") [(prms "q")]) ; to always return vector repeat? (prms "repeat") - real-chod (if (or (vector? chod) - (< chod 60)) - 94 chod) ;Never accept chod lower that 60 TODO: don't hardcode this - cache @watcher/chod-threads-cache - ] + real-chod (try ;If we can't parse number from give chod param, just use 94 + (if (or (vector? chod) + (< (Integer/parseInt chod) 60)) ; Never accept chod lower that 60 TODO: don't hardcode this + 94 (Integer/parseInt chod)) + (catch Exception e + 94)) + cache @watcher/chod-threads-cache] + ;; (println "RCVD: " rqst) + (println rqst) ;; ====== Errors ===== ;; Something other than feed.xml requested (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" "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.")}))) + ;; Whether cache has been generated yet (when (empty? cache) (throw (ex-info "503" {:status 503 :header {"Content-Type" "text/plain"} :body (str "503 Service Unavailable\n" "Cache is empty, cannot generate feed. Try again later, it may work.")}))) ;; ==== Everything good ==== - ;; (println "RCVD: " rqst) - {:status 200 - ;; 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 - :header {"Content-Type" "application/rss+xml"} - :body (generate-feed queries real-chod repeat? cache)}) + {:status 200 + ;; 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 + :header {"Content-Type" "application/rss+xml"} + :body (generate-feed queries real-chod repeat? cache)}) (catch Exception e ;; 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)