From 73c81a00a10766900318d86640249d1b54c6b351 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sat, 4 Apr 2026 16:32:16 -0500 Subject: feat: specific error messages for fetch failures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add HTTP status code checking (wttrin--extract-http-status) and pass error descriptions through the callback chain so users see "Location not found (HTTP 404)" or "Network error — check your connection" instead of the generic "Perhaps the location was misspelled?" for every failure. Also fix pre-existing bug where the condition-case error handler in extract-response-body killed an unrelated buffer after unwind-protect already cleaned up. 330 tests (was 307), all passing. --- tests/test-wttrin--get-cached-or-fetch.el | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'tests/test-wttrin--get-cached-or-fetch.el') diff --git a/tests/test-wttrin--get-cached-or-fetch.el b/tests/test-wttrin--get-cached-or-fetch.el index 75b4e8b..9bc393d 100644 --- a/tests/test-wttrin--get-cached-or-fetch.el +++ b/tests/test-wttrin--get-cached-or-fetch.el @@ -59,7 +59,7 @@ (wttrin--get-cached-or-fetch location - (lambda (data) (setq callback-result data))) + (lambda (data &optional _error-msg) (setq callback-result data))) ;; Should return cached data immediately (should (equal callback-result test-wttrin--get-cached-or-fetch-sample-weather)) @@ -88,7 +88,7 @@ (wttrin--get-cached-or-fetch location - (lambda (data) (setq callback-result data))) + (lambda (data &optional _error-msg) (setq callback-result data))) ;; Should call fetch (should fetch-called) @@ -125,7 +125,7 @@ Proactive refresh keeps data fresh; on-demand reads always use cache." (wttrin--get-cached-or-fetch location - (lambda (data) (setq callback-result data))) + (lambda (data &optional _error-msg) (setq callback-result data))) ;; Should serve old data without fetching (should-not fetch-called) @@ -160,7 +160,7 @@ Proactive refresh keeps data fresh; on-demand reads always use cache." (wttrin--get-cached-or-fetch location - (lambda (data) (setq callback-result data))) + (lambda (data &optional _error-msg) (setq callback-result data))) ;; Should fetch despite fresh cache (should fetch-called) @@ -189,7 +189,7 @@ Proactive refresh keeps data fresh; on-demand reads always use cache." (wttrin--get-cached-or-fetch location - (lambda (data) (setq callback-result data))) + (lambda (data &optional _error-msg) (setq callback-result data))) ;; Should fetch (should fetch-called) @@ -225,14 +225,14 @@ Proactive refresh keeps data fresh; on-demand reads always use cache." (let ((wttrin-unit-system "m")) (wttrin--get-cached-or-fetch location - (lambda (data) (setq callback-result data))) + (lambda (data &optional _error-msg) (setq callback-result data))) (should (equal callback-result metric-data))) ;; Fetch with imperial - should get imperial cache (let ((wttrin-unit-system "u")) (wttrin--get-cached-or-fetch location - (lambda (data) (setq callback-result data))) + (lambda (data &optional _error-msg) (setq callback-result data))) (should (equal callback-result imperial-data))))) (test-wttrin--get-cached-or-fetch-teardown))) @@ -266,7 +266,7 @@ Proactive refresh keeps data fresh; on-demand reads always use cache." (wttrin--get-cached-or-fetch location - (lambda (data) (setq callback-result data))) + (lambda (data &optional _error-msg) (setq callback-result data))) ;; Should fall back to stale cache (should (equal callback-result test-wttrin--get-cached-or-fetch-sample-weather)) @@ -296,7 +296,7 @@ Proactive refresh keeps data fresh; on-demand reads always use cache." (wttrin--get-cached-or-fetch location - (lambda (data) (setq callback-result data))) + (lambda (data &optional _error-msg) (setq callback-result data))) ;; Should return nil (no fallback available) (should (null callback-result)))) @@ -321,7 +321,7 @@ Proactive refresh keeps data fresh; on-demand reads always use cache." (wttrin--get-cached-or-fetch location - (lambda (data) (setq callback-result data))) + (lambda (data &optional _error-msg) (setq callback-result data))) ;; Should attempt to fetch (nil is a valid location input) (should fetch-called) -- cgit v1.2.3