diff options
-rw-r--r-- | bom.el | 28 |
1 files changed, 18 insertions, 10 deletions
@@ -45,11 +45,14 @@ (defun bom-api (state) "Get weather forecast data of STATE from the BOM FTP." (if-let ((filename (alist-get (intern (downcase state)) bom-state-files))) - (progn - (with-current-buffer - (find-file-noselect - (format "/ftp:anonymous@ftp.bom.gov.au:/anon/gen/fwo/%s.xml" filename)) - (libxml-parse-xml-region (point-min) (point-max)))) + (let* ((buffer (find-file-noselect + (format + "/ftp:anonymous@ftp.bom.gov.au:/anon/gen/fwo/%s.xml" + filename))) + (result (with-current-buffer buffer + (libxml-parse-xml-region (point-min) (point-max))))) + (kill-buffer buffer) + result) (user-error "State %s not found" state))) (defun bom-get-areas (resp) @@ -182,11 +185,16 @@ We use the description of the first root as the state name." (ws-start (lambda (request) (with-slots (process headers) request - (ws-response-header process 200 '("Content-type" . "text/html")) - (process-send-string - process - (bom-serve (alist-get :GET headers)) - ))) + (condition-case res + (bom-serve (alist-get :GET headers)) + (user-error (ws-send-404 process + (format "%s" (cadr res)))) + (error (ws-send-500 process)) + (:success + (ws-response-header + process 200 '("Content-type" . "text/html")) + (process-send-string process res)) + ))) bom-port))) (defun bom-stop () |