From ae1377c2176e2c64d800f412674bd8a8006cc4ff Mon Sep 17 00:00:00 2001 From: kuanyui Date: Sun, 6 Mar 2016 01:54:45 +0800 Subject: Error handling --- wttrin.el | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/wttrin.el b/wttrin.el index c370a07..ee28cbe 100644 --- a/wttrin.el +++ b/wttrin.el @@ -21,7 +21,7 @@ :group 'comm) (defcustom wttring-default-city "Taipei" - "Specify a query condition to get the weather information." + "Specify a defauly city to get the weather information." :group 'wttrin :type 'string) @@ -37,13 +37,16 @@ (defun wttrin-query (city-name) "Query weather of CITY-NAME via wttrin, and display the result in another buffer." - (let ((buf (get-buffer-create (format "*wttr.in - %s*" city-name)))) - (switch-to-buffer buf) - (insert (xterm-color-filter (wttrin-fetch-raw-string city-name))) - (goto-char (point-min)) - (re-search-forward "^$") - (delete-region (point-min) (1+ (point))) - (setq buffer-read-only t))) + (let ((raw-string (wttrin-fetch-raw-string city-name))) + (if (string-match "ERROR" raw-string) + (message "Cannot get weather data. Maybe you inputed a wrong city name?") + (let ((buffer (get-buffer-create (format "*wttr.in - %s*" city-name)))) + (switch-to-buffer buffer) + (insert (xterm-color-filter raw-string)) + (goto-char (point-min)) + (re-search-forward "^$") + (delete-region (point-min) (1+ (point))) + (setq buffer-read-only t))))) (defun wttrin (&optional force-ask) "Display weather information. -- cgit v1.2.3