aboutsummaryrefslogtreecommitdiff
path: root/tests/test-wttrin--get-cached-or-fetch.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-04-04 16:32:16 -0500
committerCraig Jennings <c@cjennings.net>2026-04-04 16:32:16 -0500
commit73c81a00a10766900318d86640249d1b54c6b351 (patch)
tree793f9c858060591c34813af05e84c7a6a5442153 /tests/test-wttrin--get-cached-or-fetch.el
parenta77a7b86f45ae96ff1802ea6f8b87dafd46b17b0 (diff)
downloademacs-wttrin-73c81a00a10766900318d86640249d1b54c6b351.tar.gz
emacs-wttrin-73c81a00a10766900318d86640249d1b54c6b351.zip
feat: specific error messages for fetch failures
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.
Diffstat (limited to 'tests/test-wttrin--get-cached-or-fetch.el')
-rw-r--r--tests/test-wttrin--get-cached-or-fetch.el20
1 files changed, 10 insertions, 10 deletions
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)